• 猴哥来了-游戏开发记录之二


    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();
                
    
            });
  • 相关阅读:
    #动态规划 0-1背包问题空间复杂度优化
    #动态规划 0-1背包问题思路概述
    #动态规划 LeetCode 337 打家劫舍 III
    #动态规划 LeetCode 213 打家劫舍 II
    #动态规划 LeetCode 198 打家劫舍
    #动态规划 LeetCode 63 不同路径 II
    #动态规划 LeetCode 62 不同路径
    #动态规划 LeetCode 279 完全平方数
    #动态规划 LeetCode 343 整数拆分
    #动态规划 LeetCode 64 最小路径和
  • 原文地址:https://www.cnblogs.com/joxin/p/9698885.html
Copyright © 2020-2023  润新知