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[] = [];
    
相关推荐
六点_dn2 分钟前
Linux学习笔记-shell运算符
linux·笔记·学习
降临-max1 小时前
软件测试基础---项目实战
软件测试·笔记·功能测试·测试用例
鱼子星_2 小时前
【C++】内存管理:内存分布,new/delete的使用及细节处理,new/delete的底层,定位new表达式
开发语言·c++·笔记
愚昧之山绝望之谷开悟之坡2 小时前
回购逆回购
笔记
鱼子星_2 小时前
【C++】string(上):string的基本使用
c++·笔记·字符串
AOwhisky2 小时前
Python 学习笔记(第四期)——字符串:格式化、操作与文本处理——核心知识点自测与详解
开发语言·笔记·python·学习·列表·元组·字典
chnyi6_ya2 小时前
论文阅读笔记 | VIDEOPHY: Evaluating Physical Commonsense for Video Generation
论文阅读·笔记
AOwhisky3 小时前
Python 学习笔记(第六期)——函数:定义、参数传递与作用域
笔记·python·学习·云原生·运维开发·函数·参数传递
玖玥拾3 小时前
Unity 3D 基础(一)Unity基础架构、物理系统、视觉渲染、空间变换与对象查询
笔记·游戏·3d·unity·游戏引擎
kdxiaojie4 小时前
Linux 驱动研究 —— V4L2 (2)
linux·运维·笔记·学习