@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