cc.Action类,是目前笔者使用CocosCreator的过程中遇到的最大的惊喜。
借助其提供的方法,可以实现很多功能。立个flag:赶明儿有时间给Unity3D封装一套。(已撸:还未完善,遇到特定需求后再慢慢添)
export default class StoneCatLaugh extends StoneCatState {
private lauchAction: cc.Action = null;
constructor(stoneCat: StoneCat, _frames: cc.SpriteFrame[]) {
super(stoneCat, _frames);
this.stoneCat.headerSprite.spriteFrame = this.frames[0];
this.lauchAction = this.setLauchAction();
this.stoneCat.node.runAction(this.lauchAction);
}
private setLauchAction() {
let moveUp = cc.moveBy(0.15, cc.v2(0, 10))
let moveDown = cc.moveBy(0.15, cc.v2(0, -10))
return cc.repeatForever(cc.sequence(moveUp, moveDown));
}
public OnLeavel() {
this.stoneCat.node.stopAllActions();
this.stoneCat.node.position = this.stoneCat.originPos;
}
public OnUpdate(dt) {
}
}
上述代码是笔者项目中的某一个功能点使用的代码。使用到了:
cc.sequence()
按顺序执行动作
cc.repeatForever()
重复某动作
cc.moveBy()
移动指定的距离
runAction()
用于指定执行action的目标节点
stopAllActions()
和stopAction()
用于停止所有动作和停止指定动作
另外除了上面函数,其它一些常用函数:
cc.moveTo()
移动到目标位置
cc.spawn()
同步执行一组动作
cc.callFunc()
执行函数
cc.delayTime()
延迟一定时间
cc.rotateBy()
旋转指定的角度
cc.rotateTo()
旋转到目标角度
cc.repeat()
重复动作,可以按一定次数重复一个动,如果想永远重复一个动作,需要使用 repeatForever 动作来完成。
cc.blink()
闪烁(基于透明度)
还有cc.scaleTo(),cc.scaleBy(),cc.bezierTo(),cc.bezierBy()等等…