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();
                
    
            });
  • 相关阅读:
    Codeforces 46D Parking Lot
    矩阵快速幂
    Codeforces 295A Greg and Array
    hihocoder 1154 Spring Outing
    51NOD 1400 序列分解
    最短路之Dijkstra算法
    连通性1 求无向图的low值
    用数组实现临接表
    hihocoder 1181 欧拉路.二
    TCP多线程聊天室
  • 原文地址:https://www.cnblogs.com/joxin/p/9698885.html
Copyright © 2011-2022 走看看