最近搜索

第6讲 界面间切换

浏览:469
管理员 2021-08-19 04:15



给按钮添加事件。

cc.Class({
    extends: cc.Component,

    properties: {
       bg1:cc.Node,
       bg2:cc.Node,
       play_node:cc.Node,
       btn_pause_node:cc.Node,
       pause_jiemian_node:cc.Node
    },
    onLoad() {
        cc.log("wx:xiaomao0055");
        cc.log("qq:14496453");
        this.bg1.y=0;
        this.bg2.y  =  this.bg1.y+this.bg1.height;
        this.isBgMove = false;
        this.bg_speed = 5;
        this.set_touch();

        this.play_node.active= true;
        this.btn_pause_node.active = false;
        this.pause_jiemian_node.active = false;

    },
    set_touch(){
        this.node.on('touchstart',function(event){
            cc.log("touchstart");
        },this);
        this.node.on('touchmove',function(event){
            cc.log("touchmove");
        },this);
        this.node.on('touchend',function(event){
            cc.log("touchend");
            this.isBgMove = true;
            this.play_node.active = false;
            this.btn_pause_node.active=true;
        },this);
    },
    setBG(){
        this.bg1.y  =  this.bg1.y-this.bg_speed;
        this.bg2.y  =  this.bg2.y-this.bg_speed;

        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;
        }
    },
    btn_click(sender,str){

        if(str=='pause'){
            this.isBgMove= false;
            this.pause_jiemian_node.active = true;
            this.btn_pause_node.active = false;
        }else if(str=='continue'){
            this.isBgMove= true;
            this.btn_pause_node.active = true;
            this.pause_jiemian_node.active = false;
        }else if(str=='back'){

        }else if(str=='restart'){
            this.play_node.active= true;
            this.btn_pause_node.active = false;
            this.pause_jiemian_node.active = false;
        }

    },
    start() {
    },
    
    update (dt) {
        if(this.isBgMove){
            this.setBG();
        }else{
            
        }
    },
});




界面之间的切换。

联系站长

站长微信:xiaomao0055

站长QQ:14496453