cocos 的笔记(不定期完善)

设计分辨率

竖屏用 720 * 1280 , Fit Width 使用宽度

横屏用 1280 * 720 , Fit Height 使用高度

背景素材 1600 * 720 或者 720 * 1600,长段到1700 也是可以的,这是为了应对 现在的大手机

图片填充

这个简单,直接缩放精灵就行,但是要选择 type 就是模式 为 tiled 模式

自定义字体

这个有点复杂,我单独写一篇文章

https://blog.csdn.net/weixin_42249565/article/details/154875595 点击这里

判断精灵是不是离开屏幕

javascript 复制代码
 // 缓冲区大小,可调整,这里是飞出去多少才死
 buffer: number = 10; 

update(deltaTime: number) {
      if (this.checkOutOfScreen()) {
          log("超出范围",this.node.x,this.node.y);
          this.destroyNode();
      }
  }
  //判断精灵是否飞出屏幕
 checkOutOfScreen(): boolean {
      const pos = this.node.getWorldPosition();
      const screen = view.getVisibleSize();
      return pos.x < -this.buffer || 
             pos.x > screen.width + this.buffer ||
             pos.y < -this.buffer || 
             pos.y > screen.height + this.buffer;
  }
   destroyNode() {
      // 销毁节点
      this.node.destroy();
      // 如果精灵节点有父节点管理,有时也需要从父节点移除
      // this.node.removeFromParent();
  }

类型设定

javascript 复制代码
 // 基本数值类型
    @property(CCInteger)
    speed: number = 5;
    
    @property(CCFloat)
    acceleration: number = 1.5;
    
    @property(CCFloat)
    jumpForce: number = 8.5;
    
    // 字符串和布尔类型
    @property(CCString)
    dogName: string = "旺财";
    
    @property(CCBoolean)
    isAlive: boolean = true;
    
    @property(CCBoolean)
    canJump: boolean = true;
    
    // 引用其他组件或节点
    @property(Node)
    target: Node = null;
    
    @property(Sprite)
    dogSprite: Sprite = null;
    
    // 向量和颜色
    @property(Vec2)
    initialPosition: Vec2 = new Vec2(0, 0);
    
    @property(Color)
    dogColor: Color = Color.WHITE;
    
    // 数组类型
    @property([CCInteger])
    speedLevels: number[] = [1, 2, 3, 5, 8];
    
    @property([Node])
    waypoints: Node[] = [];
    
相关推荐
冷雨夜中漫步7 小时前
Python快速入门(6)——for/if/while语句
开发语言·经验分享·笔记·python
Gain_chance10 小时前
34-学习笔记尚硅谷数仓搭建-DWS层最近一日汇总表建表语句汇总
数据仓库·hive·笔记·学习·datagrip
Gain_chance11 小时前
36-学习笔记尚硅谷数仓搭建-DWS层数据装载脚本
大数据·数据仓库·笔记·学习
肖永威11 小时前
macOS环境安装/卸载python实践笔记
笔记·python·macos
暗光之痕12 小时前
Unreal5研究笔记 Actor的生命周期函数
笔记·unreal engine
Gain_chance12 小时前
35-学习笔记尚硅谷数仓搭建-DWS层最近n日汇总表及历史至今汇总表建表语句
数据库·数据仓库·hive·笔记·学习
宵时待雨12 小时前
STM32笔记归纳9:定时器
笔记·stm32·单片机·嵌入式硬件
m0_7190841113 小时前
React笔记张天禹
前端·笔记·react.js
r i c k15 小时前
数据库系统学习笔记
数据库·笔记·学习
shandianchengzi16 小时前
【小白向】错位排列|图文解释公考常见题目错位排列的递推式Dn=(n-1)(Dn-2+Dn-1)推导方式
笔记·算法·公考·递推·排列·考公