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


    .CocosCretor版本3.2.1

    编辑器VScode

    制作游戏背景的循环滚动

    1. import { _decorator, Component, Node } from 'cc';
    2. const { ccclass, property } = _decorator;
    3. @ccclass('MoveingSceneBg')
    4. export class MoveingSceneBg extends Component {
    5. @property(Node)
    6. bg01: Node = null!;
    7. @property (Node)
    8. bg02: Node = null!;
    9. private _bgSpeed= 10;
    10. private _bgMovingRange =90;
    11. // [1]
    12. // dummy = '';
    13. // [2]
    14. // @property
    15. // serializableDummy = 0;
    16. start () {
    17. this._Init();
    18. // [3]
    19. }
    20. update (deltaTime: number) {
    21. this._moveBackGround(deltaTime);
    22. }
    23. private _Init(){
    24. this.bg01.setPosition(0,0,0);
    25. this.bg02.setPosition(0,0,-this._bgMovingRange);
    26. }
    27. private _moveBackGround(deltaTime: number){
    28. this.bg01.setPosition(0,0,this.bg01.position.z +this._bgSpeed*deltaTime );
    29. this.bg02.setPosition(0,0,this.bg02.position.z +this._bgSpeed*deltaTime );
    30. if(this.bg01.position.z > this._bgMovingRange){
    31. this.bg01.setPosition(0,0,this.bg02.position.z - this._bgMovingRange);
    32. }else if (this.bg02.position.z > this._bgMovingRange){
    33. this.bg02.setPosition(0,0,this.bg01.position.z - this._bgMovingRange);
    34. }
    35. }
    36. }
    37. /**
    38. * [1] Class member could be defined like this.
    39. * [2] Use `property` decorator if your want the member to be serializable.
    40. * [3] Your initialization goes here.
    41. * [4] Your update function goes here.
    42. *
    43. * Learn more about scripting: https://docs.cocos.com/creator/3.0/manual/en/scripting/
    44. * Learn more about CCClass: https://docs.cocos.com/creator/3.0/manual/en/scripting/ccclass.html
    45. * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.0/manual/en/scripting/life-cycle-callbacks.html
    46. */

  • 相关阅读:
    python打包技巧:彻底解决pyinstaller打包exe文件太大的问题
    SpringBoot+Vue实现AOP系统日志功能
    STC 51单片机46——看门狗测试
    为什么 Java 不支持多重继承?
    进程和线程、协程的区别
    ISC技术分享:从RASP开启云上应用安全防护
    Oracle 遍历变量游标
    Linux 安全 - 内核提权
    JavaScript构造函数和原型:继承
    CSS布局:Flex布局
  • 原文地址:https://blog.csdn.net/weixin_39114763/article/details/134274754