CVP认证学习笔记--李天宇019实现帧动画处理

    首先先总结一下帧动画的步骤:①spriteanimationanimatesprite.runAction

    下面让我们来看一下具体的实现步骤:

var HelloWorldLayer = cc.Layer.extend({

    ctor:function(){

        this._super();

        var size = cc.winSize;

        var bg = new cc.Sprite(res.bg_jpg);

        this.addChild(bg);

        bg.setPosition(size.width/2,size.height/2);

        //添加动画

        var sp = new cc.Sprite();

        sp.setTag(100);

        var animation = new cc.Animation();

        for(var i=1;i<=5;i++){

            var frameName = "res/"+"walk0"+i+".png";

            animation.addSpriteFrameWithFile(frameName);

        }

        animation.setDelayPerUnit(0.1);

        var animate = cc.animate(animation);

        this.addChild(sp);

        sp.runAction(cc.repeatForever(animate));

        sp.setPosition(200,200);

        return true;

}

可以看出我们通过一组for循环通过字符串连接的形式将每一帧的精灵进行添加操作。设置帧率(帧率越高,播放的越慢),然后按照步骤即可播放帧动画,如果需要循环播放则需要用到cc.repeatforever

最后附上作业链接:

http://www.cocoscvp.com/usercode/2016_04_24/b903c70568416cbe3f1136a8c593b889b4443e1f/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值