Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 88737

新人求助:cocos creater跳跃动作脚本

$
0
0

@inari 写道:

新人求助贴

用cocos creater的jumpBy方法实现的跳跃动作脚本,现在的状况是短按空格键,动作很正常,但是长按的话节点就会飘在空中,应该怎么改?

 cc.Class({
extends: cc.Component,

properties: {
   
    jumpDuration:0,
    jumpHeight:0,
},
setInputControl: function()
{
    var self = this;
    cc.eventManager.addListener(
    {
        event:cc.EventListener.KEYBOARD,
        onKeyPressed: function(keyCode,event)
        {
            if(keyCode==cc.KEY.space)
            {
                self.wthJump = true;
            }
        },
        onKeyReleased: function(keyCode,event)
        {
            if(keyCode==cc.KEY.space)
            {
                self.wthJump = false;
            }
        },
    }, self.node);
},
    
setJump: function()
{
    var actionBy= cc.jumpBy(this.jumpDuration, cc.p(0,0),this.jumpHeight, 1);
    this.node.runAction(actionBy);
},


onLoad: function () {
    this.wthJump= false;
    this.setInputControl();
},

update:function(dt){
    if(this.wthJump)
    {
        this.setJump();
    }
}
},
});

帖子: 4

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 88737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>