import GameScene from "../scene/GameScene";
const {ccclass, property} = cc._decorator;
@ccclass
export default class ControlMyAnimation extends cc.Component {
private isPlayAnimation:boolean=false;
// LIFE-CYCLE CALLBACKS:
private myAnimation:cc.Animation;
// onLoad () {}
private GameSceneScript:GameScene;
private thisId:number;
start () {
this.myAnimation=this.node.getComponent(cc.Animation);
this.myAnimation.stop();
this.isPlayAnimation=false;
this.GameSceneScript=cc.find("Canvas").getComponent(GameScene);
if(this.node.name=="weapon1Bigger")
{
this.thisId=1;
console.log(this.node.name+" "+this.thisId);
}
else if(this.node.name=="hand")
{
this.thisId=2;
}
this.node.zIndex=1;
}
update (dt) {
if(!this.isPlayAnimation)
{
if(this.GameSceneScript._currentStep==this.thisId)
{
this.myAnimation.play();
this.isPlayAnimation=true;
console.log("正在播放中");
}
}
}
}
上边就是Cocos里边playAnimation的一些用法