cocos2dx创建精灵动作

玩游戏的都知道,hero没有动作,无论是走路,还是打架,都像站在滑板车上,像鬼魂一样平移的飘来飘去,那是一种令人何其惊悚的景象呀!

所以在精灵设计的时候,我们需要给精灵添加一定的动作,比如走路时,脚动,打架时,手舞足蹈,打有打姿,跑有跑姿,这样才够自然,因此我们需要用到cocostudio工具来生成plist文件,再使用这些资源配置来给精灵设置动作。(ps:cocostudio到官方网站下载对应系统的版本,至于使用,网上有很多资料)

话不多说了,开始这篇博客的旅程,


CCSprite *arrow = CCSprite::create("dammer0.png");//创建精灵初始状态
CCSpriteFrameCache *arrowCache = CCSpriteFrameCache::sharedSpriteFrameCache();
arrowCache->addSpriteFramesWithFile("dammer.plist","dammer.png");//加载plist文件
CCSpriteFrame * arrowFrame = NULL;
CCArray *arrowArray = CCArray::create();
for(int i=1;i<3;i++)
{
	arrowFrame = arrowCache->spriteFrameByName(CCString::createWithFormat("dammer%d.png",i)->getCString());
	arrowArray->addObject(arrowFrame);//添加帧动画
}
CCAnimation *arrowAnimation = CCAnimation::createWithSpriteFrames(arrowArray);//创建帧动画
arrowAnimation->setLoops(1);//设置帧动画动作循环次数,-1为无限循环
arrowAnimation->setDelayPerUnit(0.08f);//设置每帧动画的时延
CCAnimate *arrowAnimate = CCAnimate::create(arrowAnimation);//创建动画动作
arrow->runAction(arrowAnimate);//精灵添加动作


最后结果如上图所示!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值