Cocos Creator TypeScript 使用createWithSpriteFrames实现动态创建动画Animation,并播放

本文介绍了如何在Cocos Creator 1.9版本中使用TypeScript和createWithSpriteFrames动态创建动画组件,解决了编辑器内动画制作的bug问题,提供了源码示例和显示效果。
摘要由CSDN通过智能技术生成

希望可以帮到刚入坑的新人

直接给小伙伴分享刚完成的源码:

const {ccclass, property} = cc._decorator;

/**
 * @author Maniac.guo
 * Everyone should have a dream , what if it came true ?
 * @className 动画组件(动态创建动画Animation)
 * @data 2018年5月18日
 * @mailbox 309506117@qq.com
 */
@ccclass
export class AnimationComponent extends cc.Component {

    @property(cc.SpriteAtlas)
    sprAtlas:cc.SpriteAtlas = null;
    @property(Number)
    wrapMode:cc.WrapMode = cc.WrapMode.Default;

    private _animation:cc.Animation;

    public onPlayCallBack:Function = null;
    public onStopCallBack:Function = null;
    public onFinishedCallBack:Function = null;

    onLoad () {
        this._animation = this.node.getComponent(cc.Animation);
        // console.log(this.sprAtlas);
        this.setAnimation();
    }

    public setAnimation() : void {
        let self = this;
        if(t
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值