当前位置: 首页 > news >正文

CocosCreator:背景滚动 、背景循环滚动

.CocosCretor版本3.2.1

编辑器VScode

制作游戏背景的循环滚动


import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;@ccclass('MoveingSceneBg')
export class MoveingSceneBg extends Component {@property(Node)bg01: Node = null!;@property (Node)bg02: Node = null!;private _bgSpeed= 10;private _bgMovingRange =90;// [1]// dummy = '';// [2]// @property// serializableDummy = 0;start () {this._Init();// [3]}update (deltaTime: number) {this._moveBackGround(deltaTime);}private _Init(){this.bg01.setPosition(0,0,0);this.bg02.setPosition(0,0,-this._bgMovingRange);}private _moveBackGround(deltaTime: number){this.bg01.setPosition(0,0,this.bg01.position.z +this._bgSpeed*deltaTime );this.bg02.setPosition(0,0,this.bg02.position.z +this._bgSpeed*deltaTime );if(this.bg01.position.z > this._bgMovingRange){this.bg01.setPosition(0,0,this.bg02.position.z   - this._bgMovingRange);}else if    (this.bg02.position.z > this._bgMovingRange){this.bg02.setPosition(0,0,this.bg01.position.z   - this._bgMovingRange);}
}
}/*** [1] Class member could be defined like this.* [2] Use `property` decorator if your want the member to be serializable.* [3] Your initialization goes here.* [4] Your update function goes here.** Learn more about scripting: https://docs.cocos.com/creator/3.0/manual/en/scripting/* Learn more about CCClass: https://docs.cocos.com/creator/3.0/manual/en/scripting/ccclass.html* Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.0/manual/en/scripting/life-cycle-callbacks.html*/

http://www.lryc.cn/news/221752.html

相关文章:

  • 中远麒麟堡垒机SQL注入漏洞复现
  • ActiveMq学习⑨__基于zookeeper和LevelDB搭建ActiveMQ集群
  • Ansible概述以及模块
  • Cannot run program “D:\c\IntelliJ IDEA 2021.1.3\jbr\bin\java.exe“
  • 案例-注册页面(css)
  • Ansible--playbook 剧本
  • Vue3.0路由拦截
  • EtherCAT转EtherNET/IP协议网关控制EtherCAT伺服驱动器的方法
  • 钉钉内嵌H5遇到的一些问题
  • LeetCode 热题100——链表专题(二)
  • 【Rust日报】2023-11-06 ESP上使用 Rust实现 SNTP协议
  • LibreOJ - 2874 历史研究 (回滚莫队)
  • 人工智能-卷积神经网络之多输入多输出通道
  • Open3D(C++) Umeyama算法求两个点云的变换矩阵
  • 【C++】从入门到精通第二弹——类的构造与析构函数
  • C#8.0本质论第十一章--异常处理
  • FPGA高端项目:图像缩放+GTP+UDP架构,高速接口以太网视频传输,提供2套工程源码加QT上位机源码和技术支持
  • ansible安装和常见模块
  • 【Python基础】 Python设计模式之单例模式介绍
  • 算法小白的心得笔记:关于Nan
  • Photoshop 2023 v24.7
  • 进程间通信(IPC)-管道、消息队列、信号量、共享存储、socket
  • 「Verilog学习笔记」使用generate…for语句简化代码
  • 互联网Java工程师面试题·Spring篇·第七弹
  • mysql驱动包引起的告警问题using SSL the verifyServerCertificate property is set to ‘false‘
  • draw.io与项目管理——如何利用流程图工具提高项目管理效率
  • LoRaWAN物联网架构
  • 数据结构(五):哈希表及面试常考的算法
  • 水利部加快推进小型水库除险加固,大坝安全监测是重点
  • 实施电子采购的6个有效步骤