八 手游开发神器 cocos2d-x editor 之动画和帧动画

一个游戏的成功很大程度上取决于动画的成功,熟悉cocos2dx的读者都知道它具备了很多现成的动画。这一节我将实现小怪物慢慢的摇摇晃晃的向前走;


运行效果如下





代码下载地址:http://www.kuaipan.cn/file/id_25348935635744616.htm?source=1



首先新建一个帧动画文件,Resorces-----New----FramesAnimation,命名确定,创建snow_frame.plish成功




安装下图操作,创建一组帧动画,也可在xml文件调节修改;(提示 不是把整个文件snow.packer.plist拖进去 打开加号找到单独的一个.plist文件,图示有误)



创建成功后,把图片里面的第一帧作为精灵创建,调节好参数




打开MainLayer.js,编写代码如下,帧动画的同时向前移动:

//
// CleanerScoreScene class
//
var MainLayer = function () {
    cc.log("MainLayer")
    this.scoreLabel = this.scoreLabel || {};
    this.monster = this.monster || {};
    this.score = 123;
};

MainLayer.prototype.onDidLoadFromCCB = function () {
    if (sys.platform == 'browser') {
        this.onEnter();
    }
    else {
        this.rootNode.onEnter = function () {
            this.controller.onEnter();
        };
    }

    this.rootNode.schedule(function (dt) {
        this.controller.onUpdate(dt);
    });

    this.rootNode.onExit = function () {
        this.controller.onExit();
    };
};

MainLayer.prototype.onEnter = function () {
    cc.AnimationCache.getInstance().addAnimations("Resources/snow_frame.plist");//添加帧动画文件
    var action0 = cc.Sequence.create(cc.MoveTo.create(30, cc.p(360, 200)));  //向前移动
    var actionFrame = cc.Animate.create(cc.AnimationCache.getInstance().getAnimation("monster"));   //获取帧动画
    var action1 = cc.Repeat.create(actionFrame, 90000);
    var action2 = cc.Spawn.create(action0, action1); //同步动画
    this.monster.runAction(action2);
}

MainLayer.prototype.onUpdate = function (dt) {
    this.score += dt;
    this.scoreLabel.setString(Math.floor(this.score));
}

MainLayer.prototype.onExitClicked = function () {
    cc.log("onExitClicked");
}


MainLayer.prototype.onExit = function () {
    cc.log("onExit");
}

cc.Animate.createWithName = function (name) {
    return cc.Animate.create(cc.AnimationCache.getInstance().getAnimation(name));
}


下一篇文章 我会介绍cocos2d-x  editor的粒子效果       笔者(李元友)

资料来源:cocos2d-x  editor

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值