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

编程入门 行业动态 更新时间:2024-10-07 12:20:21

CocosCreator:<a href=https://www.elefans.com/category/jswz/34/1771046.html style=背景滚动 、背景循环滚动"/>

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: .0/manual/en/scripting/* Learn more about CCClass: .0/manual/en/scripting/ccclass.html* Learn more about life-cycle callbacks: .0/manual/en/scripting/life-cycle-callbacks.html*/

更多推荐

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

本文发布于:2023-11-16 02:19:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1611757.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:背景   CocosCreator

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!