cocos2dx 精灵动作优化
来源:互联网 发布:浙江网络名师工作室 编辑:程序博客网 时间:2024/05/01 23:18
精灵的概念这里就不说了,论坛上有很多。
一、今天的问题是:如果我有一套美术资源,如一个羊的素材(当然是png),它有站立 ,有跑步,有行走动作。如果当前要加载两个这样的羊,我们该怎么做?
1.第一种方法,想必大家都知道 加载2次。
当然这样有的话,如果我要100个难道也要加载100次的Animation吗?显然不是
2.第二种方法 这里我就按照自己的理解注释了
#define SHEEP_STAND "sheep_stand"#define SHEEP_RUN "sheep_run"#define SHEEP_BATTACK "sheep_battack" //创建帧缓冲 CCSpriteFrameCache *sheepFrameCache =CCSpriteFrameCache::sharedSpriteFrameCache(); sheepFrameCache->addSpriteFramesWithFile("sheep.plist"); //创建动作缓冲 CCAnimationCache *sheepAniCache = CCAnimationCache::sharedAnimationCache();
cocos2dx中CCAnimationCache是单例 可以直接取到不用创建
CCAnimationCache *SpriteAni = CCAnimation::create(); for(int i=1;i<7;i++) { char szName[100] = {0}; sprintf(szName, "stand/stand%d.png",i); CCLog("%s",szName); CCSpriteFrame *SFrame = sheepFrameCache->spriteFrameByName(szName); SpriteAni->addSpriteFrame(SFrame); } sheepAniCache->addAnimation(SpriteAni, SHEEP_STAND);
这样我就加入到了动作缓冲中 下次要是再使用的时候就可以:
SpriteAni = sheepAniCache->animationByName(SHEEP_STAND);
OK 怎么加载动作的话大家一概自己清楚
CCFiniteTimeAction *action = CCSequence::create(aniStart, CCAnimate::create(SpriteAni,aniEnd,NULL);
然后runAction就可以了!
二、减少绘制 引入CCSpriteBatchNode类
CCSpriteBatchNode *parent2 = CCSpriteBatchNode::create("sheep.pvr.ccz"); addChild(parent2); CCSprite *sh1 = CCSprite::create("1.png"); parent2->addChild(sh1); CCSprite *sh2 = CCSprite::create("2.png"); parent2->addChild(sh2);cocos2dx作者解释:
// Animation using Sprite batch // // A CCSpriteBatchNode can reference one and only one texture (one .png file) // Sprites that are contained in that texture can be instantiatied as CCSprites and then added to the CCSpriteBatchNode // All CCSprites added to a CCSpriteBatchNode are drawn in one OpenGL ES draw call // If the CCSprites are not added to a CCSpriteBatchNode then an OpenGL ES draw call will be needed for each one, which is less efficient
- cocos2dx 精灵动作优化
- cocos2dx创建精灵动作
- cocos2dx中精灵的动作
- cocos2dx中精灵如何run一个动作
- cocos2dx 多个精灵执行同一个动作
- cocos2dx对精灵的优化
- cocos2dx对精灵的优化
- Cocos2dx对精灵的优化
- cocos2dx对精灵的优化
- cocos2dx-3.x 精灵设置颜色以及动作速度调整
- cocos2dx自学之路 精灵执行动作+TableView控件
- cocos2dx 持续学习(一) 声音、精灵、动作
- cocos2dx 动作
- Cocos2dX动作
- cocos2dx-动作
- cocos2dx多个精灵调用runAction()方法执行组合动作,只有最后一个精灵有效的问题
- cocos2dx 3.2中精灵帧动画的使用以及动作组合
- Cocos2dx项目--动作类游戏内存优化--Spine结构分析
- 三十分钟掌握STL
- 伤感心情日志_没有一丝安稳能让我落脚
- 修改Oracle SQL Developer的时间格式
- linux下修改mysql的root密码
- db2字符串函数
- cocos2dx 精灵动作优化
- 十八. Sql server视图的创建
- 【错误收录】IOException while loading persisted sessions
- zabbix权限分配详解
- hadoop集群安装
- 一定要知道的 Web 设计八个流行趋势
- 程序人生
- 记得依依曾经说过,要做个快乐的天使。
- 十九.Sql server中索引的创建