cocos2dx-3.0角色动画

前端之家收集整理的这篇文章主要介绍了cocos2dx-3.0角色动画前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. //将plist加载进精灵帧缓存,提及了plist的优点(@@@-1-@@@)
  2. SpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("role.plist");
  3. //读取图片,存到精灵帧容器中
  4. Vector<SpriteFrame*> attackVector;
  5. for (int index=1;index!=9;++index)
  6. { //CCLOG向控制台输出信息,便于调试
  7. CCLOG(String::createWithFormat("%s%d.png","Img_Zhici",index)->getCString());
  8. attackVector.pushBack( SpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(String::createWithFormat("%s%d.png",index)->getCString()) );//这里是关键的地方,和添加图片到精灵帧不同:SpriteFrame::create
  9. }
  10. Animation *animation1=Animation::createWithSpriteFrames(attackVector,0.1f);
  11. Animate *attack1=Animate::create(animation1);
  12.  
  13. //创建攻击类型1 精灵
  14. Sprite * sp=Sprite::create();
  15. sp->setPosition(ccp(visibleSize.width/4,visibleSize.height/3));
  16. this->addChild(sp);
  17.  
  18. //执行动作 forerver
  19. sp->runAction(RepeatForever::create(attack1));
  20. //释放plist
  21. SpriteFrameCache::sharedSpriteFrameCache()->removeSpriteFramesFromFile("role.plist");

@@@-1-@@@

TexturePacker制作plist,使用plist的好处:

(1)提高载入速度

拼成大图,一次载入,减少I/O,提高速度

(2)减少内存

OpenGL ES纹理的宽和高都需要2次幂数,在载入内存后,

使用TexturePacker打包后它其实会被变成512x512的纹理,进而减少内存的使用

(3)加快渲染速度

OpenGLES渲染图片是需要使用glDrawArray,一张纹理调用一次,打包后,减少了glDrawArray的使用

详见:http://www.jb51.cc/article/p-uhujfzry-bky.html


留下问题:

this->schedule(schedule_selector:这个到底是什么?

是否Enemy相对于Hero,可以将其行为(特指动画)封装在一个函数中,供布景主例程调用(需要判断与Hero的关系来运作,特指人工智能部分;但似乎可以封装在Enemy中),作为感性认识上的场景一部分?

注:表达不清←。←


效果如图

猜你在找的Cocos2d-x相关文章