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[] = [];
    
相关推荐
云原生指北2 小时前
你的数据正在喂养 AI:从 Atlassian 公告,看科技平台的数据训练默认政策
笔记
**蓝桉**3 小时前
容器服务学习笔记
笔记·学习
zhangrelay4 小时前
三分钟云课实践速通--模拟电子技术-模电--SimulIDE
linux·笔记·学习·ubuntu·lubuntu
木木_王4 小时前
嵌入式Linux学习 | 数据结构 (Day05) 栈与队列详解(原理 + C 语言实现 + 实战实验 + 易错点剖析)
linux·c语言·开发语言·数据结构·笔记·学习
lkforce4 小时前
MiniMind学习笔记(三)--train_pretrain.py(预训练)
笔记·机器学习·ai·预训练·minimind·train_pretrain
OSwich4 小时前
【 Godot 4 学习笔记】数组(Array)
笔记·学习·godot
数据皮皮侠AI5 小时前
中国城市可再生能源数据集(2005-2021)|顶刊 Sci Data 11 种能源面板
大数据·人工智能·笔记·能源·1024程序员节
其实防守也摸鱼5 小时前
面试常问问题总结--护网蓝队方向
网络·笔记·安全·面试·职场和发展·护网·初级蓝队
z19408920666 小时前
Word题库转结构化:告别换行、选项与答案乱象
经验分享·笔记·语音识别
泽克7 小时前
3.4 智能化系统工程施工技术
笔记