cocos2dx创建精灵动作
2014-06-25 17:52
344 查看
玩游戏的都知道,hero没有动作,无论是走路,还是打架,都像站在滑板车上,像鬼魂一样平移的飘来飘去,那是一种令人何其惊悚的景象呀!
所以在精灵设计的时候,我们需要给精灵添加一定的动作,比如走路时,脚动,打架时,手舞足蹈,打有打姿,跑有跑姿,这样才够自然,因此我们需要用到cocostudio工具来生成plist文件,再使用这些资源配置来给精灵设置动作。(ps:cocostudio到官方网站下载对应系统的版本,至于使用,网上有很多资料)
话不多说了,开始这篇博客的旅程,
最后结果如上图所示!
所以在精灵设计的时候,我们需要给精灵添加一定的动作,比如走路时,脚动,打架时,手舞足蹈,打有打姿,跑有跑姿,这样才够自然,因此我们需要用到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);//精灵添加动作
最后结果如上图所示!
相关文章推荐
- cocos2dx四种创建精灵的方法
- 动作编辑器(Cocos2dx)制作流程详解及附上响应鼠标滚轴事件、反转坐标系、导入/创建资源目录等知识点代码
- cocos2dx 通过plist文件 创建精灵
- cocos2dx-3.0以上版本之 创建Sprite精灵的6种形式
- cocos2dx多个精灵调用runAction()方法执行组合动作,只有最后一个精灵有效的问题
- [cocos2dx-lua]Cocos2dx-Lua中Sprite精灵的3种创建方法
- 【Cocos2dX(2.x)_Lua开发之三】★重要必看篇★在Lua中使用自定义精灵(Lua脚本与自创建类之间的访问)及Lua基础讲解
- cocos2dx创建精灵的五种方法
- cocos2dx-3.x 精灵设置颜色以及动作速度调整
- cocos2dx创建精灵的方法
- 小鬼学cocos2dX笔记01——创建精灵动画(一)
- cocos2dx 精灵动作优化
- 【cocos2dx】如何创建自己定义的精灵类Sprite
- quick -- 创建精灵和动作
- cocos2dx-3.2之创建精灵和简单运动
- 【cocos2dx】创建精灵的两种方法
- cocos2dx 创建精灵的5种方式
- 【Cocos2dX(2.x)_Lua开发之三】★重要必看篇★在Lua中使用自定义精灵(Lua脚本与自创建类之间的访问)及Lua基础讲解
- 动作编辑器(Cocos2dx)制作流程详解及附上响应鼠标滚轴事件、反转坐标系、导入/创建资源目录等知识点代码!
- cocos2dx项目创建精灵 提取版