Creator 动画高级用法之帧事件

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Sprite)
    test: cc.Sprite = null;

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        let animation= this.test.getComponent(cc.Animation);
        animation.play("test");
        // animation.pause("test");

        // 获取AnimationState的方法:
        let animState = animation.getAnimationState('test');
       // 修改播放速度参数使动画减速
        animState.speed = 0.1;
        
        // 动画系统支持动态注册回调事件

        // 注册
        animation.on('play', this.onPlay, this);
        // 取消注册
        // animation.off('play', this.onPlay, this);
        animation.on('stop',      this.onStop,        this);
        // animation.on('lastframe', this.onLastFrame,   this);
        animation.on('finished',  this.onFinished,    this);
        animation.on('pause',     this.onPause,       this);
        animation.on('resume',    this.onResume,      this);


        // 对单个 cc.AnimationState 注册回调
        var animSteate = animation.getAnimationState('test');
        animState.on('lastframe',this.onLastFrame, this);
            
    }

    onPlay() {
        console.log("==>this.onPlay");
    }


    onStop() {
        console.log("==>this.onStop");

    }

    onFinished() {
        console.log("==>this.onFinish");

    }

    onPause() {
        console.log("==>this.onPause");

    }

    onResume(){
        console.log("==>this.onResume");
    }

    onLastFrame (){
        console.log("==>this.onLastFrame");
    }

    onAnimCompleted (num: Number, string:String) {
        console.log('==>onAnimCompleted: param1[%s], param2[%s]', num, string);
    }

    start () {

    }

    // update (dt) {}
}

参考:https://blog.csdn.net/qq_34501940/article/details/80425167

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值