最近搜索

第2讲 创建循环背景

浏览:482
管理员 2021-08-18 04:09


弄2个背景。代码如下。

image.png



cc.Class({
    extends: cc.Component,

    properties: {
       bg1:cc.Node,
       bg2:cc.Node
    },
    onLoad() {
        cc.log("wx:xiaomao0055");
        cc.log("qq:14496453");
        this.bg1.y=0;
        this.bg2.y  =  this.bg1.y+this.bg1.height;
    },
    start() {
    },
    update (dt) {
            this.bg1.y  =  this.bg1.y-10;
            this.bg2.y  =  this.bg2.y-10;

            if(this.bg1.y<= -this.bg1.height){
                this.bg1.y=this.bg2.y+this.bg1.height;
            }
            if(this.bg2.y<= -this.bg1.height){
                this.bg2.y=this.bg1.y+this.bg1.height;
            }
            console.log(this.bg1.y)
    },
});


联系站长

站长微信:xiaomao0055

站长QQ:14496453