Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17070

Press Key and Play Animation

$
0
0

@luke2125 wrote:

Hi,

I'm working with Cocos Creator, and trying to set up when player presses key, it will play an animation I've set up and saved, please see below:

testrunleftanimation: function(){
var testingrunleft = this.getComopnent(cc.Animation);
this.testingrunleft.play('testingrunleftanim');
},

setInputControl: function () {
var self = this;
// add keyboard event listener
cc.eventManager.addListener({
event: cc.EventListener.KEYBOARD,
// When there is a key being pressed down, judge if it's the designated directional button and set up acceleration in the corresponding direction
onKeyPressed: function(keyCode, event) {
switch(keyCode) {
case cc.KEY.a:
self.accLeft = true;
self.accRight = false;
this.testrunleftanimation();
break;
case cc.KEY.d:
self.accLeft = false;
self.accRight = true;
break;
}
},

I've also added the animation component to the node which is player, and I've included the 2 animations in the animclip within the component, and play on load to false. However, when I press it doesn't play the animation on the player ( character ). What piece am I missing? Any help or insight would be appreciated it.....Thanks and God Bless...

Sincerely,

Sunday

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 17070

Trending Articles



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