zoukankan      html  css  js  c++  java
  • 猴哥来了-游戏开发记录之二

    1、node和u3d中的gameobject相似。
    2、事件(鼠标事件和触屏事件的定义方式和原理还有些模糊。需要进一步学习)
    2.1 点击事件可以通过回调方式挂载
    // LIFE-CYCLE CALLBACKS:
        btnClick(event, customEventData){
            //console.log("event=",event.type," data=",customEventData);        
           };
    
        onLoad () {
            
            let self = this;
    2.2 也可单独写脚本挂载node上
    const {ccclass, property} = cc._decorator;
    import Global = require("./GlobalEvents");
    
    @ccclass
    export default class NewClass extends cc.Component {    
    
        @property(cc.Button)
        btnplay: cc.Button = null;
    
        @property(cc.Button)
        btnsound: cc.Button = null;
    
        @property(cc.Button)
        btnmusic: cc.Button = null;
    
        @property(cc.Button)
        btntotal: cc.Button = null;
    
        @property(cc.SpriteFrame)
        soundenbPic: cc.SpriteFrame = null;
    
        @property(cc.SpriteFrame)
        sounddisPic: cc.SpriteFrame = null;
    
        @property(cc.SpriteFrame)
        musicenbPic: cc.SpriteFrame = null;
    
        @property(cc.SpriteFrame)
        musicedisPic: cc.SpriteFrame = null;
    
        // LIFE-CYCLE CALLBACKS:
    
        onLoad () {
    
            var self = this;
    
            //加载按钮动画事件        
            self.btnsound.node.on(cc.Node.EventType.TOUCH_START, function (event) {
                //console.log(' TOUCH_START');
            });
    
            self.btnsound.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
                //console.log(' TOUCH_MOVE');
                self.btnsound.getComponent(cc.Animation).play();           
                
            });
    
            self.btnsound.node.on(cc.Node.EventType.TOUCH_END, function (event) {
                //console.log(' TOUCH_END');
                self.btnsound.getComponent(cc.Animation).stop();
                //换图片
                if(Global.isSound==1){
                    //Global.isSound = 0;  
                    self.btnsound.getComponent(cc.Sprite).spriteFrame = self.sounddisPic;
                }
                else{
                    //Global.isSound = 1;
                    self.btnsound.getComponent(cc.Sprite).spriteFrame = self.soundenbPic;
                }
                
            });
    
            self.btnsound.node.on(cc.Node.EventType.TOUCH_CANCEL, function (event) {
                //console.log(' TOUCH_CANCEL');
                self.btnsound.getComponent(cc.Animation).stop();
    
            });
    
            self.btnsound.node.on(cc.Node.EventType.MOUSE_ENTER, function (event) {
                //console.log(' MOUSE_ENTER');
                self.btnsound.getComponent(cc.Animation).play();
            });
    
            self.btnsound.node.on(cc.Node.EventType.MOUSE_LEAVE, function (event) {
                //console.log(' MOUSE_LEAVE');
                self.btnsound.getComponent(cc.Animation).stop();
                
    
            });
  • 相关阅读:
    React生命周期, 兄弟组件之间通信
    React组件式编程Demo-用户的增删改查
    React之this.refs, 实现数据双向绑定
    CCF CSP 201812-4 数据中心
    CCF CSP 201812-4 数据中心
    PAT 顶级 1020 Delete At Most Two Characters (35 分)
    PAT 顶级 1020 Delete At Most Two Characters (35 分)
    Codeforces 1245C Constanze's Machine
    Codeforces 1245C Constanze's Machine
    CCF CSP 201712-4 行车路线
  • 原文地址:https://www.cnblogs.com/joxin/p/9698885.html
Copyright © 2011-2022 走看看