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

新人求指导 “用update不能实现自动循环播放”

$
0
0

@zimson 写道:

cc.Class({
extends: cc.Component,

onLoad () {
var self = this;
cc.eventManager.addListener({
event: cc.EventListener.KEYBOARD,
onKeyPressed: function(keyCode, event)
{
self._onKeyPressed(keyCode, event);
}
}, self.node);
},

update: function (dt) {
this._timer += dt;
if ( this._timer >= 5.0 ) {
this. playani();
this._timer = 0.0;
}},

playani() {
var anim = this.getComponent(cc.Animation);
anim.play('ani1');
},

_onKeyPressed: function(keyCode, event) {
var anim = this.getComponent(cc.Animation);
switch(keyCode) {
case cc.KEY.a:
anim.play('ani2');
break;
case cc.KEY.b:
anim.play('ani3');
break;
default:
return;
} },
}
);

键盘能控制播放动画,但是用update不能实现自动循环播放

帖子: 12

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 88737

Trending Articles