cocos2dx-3.0角色动画

	  	//将plist加载进精灵帧缓存,提及了plist的优点(@@@-1-@@@)
		SpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("role.plist");
		//读取图片,存到精灵帧容器中
		Vector<SpriteFrame*> attackVector;
		for (int index=1;index!=9;++index)
		{	//CCLOG向控制台输出信息,便于调试
			CCLOG(String::createWithFormat("%s%d.png","Img_Zhici",index)->getCString());
			attackVector.pushBack(  SpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(String::createWithFormat("%s%d.png",index)->getCString())   );//这里是关键的地方,和添加图片到精灵帧不同:SpriteFrame::create
		}
	
		Animation *animation1=Animation::createWithSpriteFrames(attackVector,0.1f);
		Animate *attack1=Animate::create(animation1);

		//创建攻击类型1 精灵
		Sprite * sp=Sprite::create();
		sp->setPosition(ccp(visibleSize.width/4,visibleSize.height/3));
		this->addChild(sp);

		//执行动作 forerver
		sp->runAction(RepeatForever::create(attack1));
		//释放plist
		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中),作为感性认识上的场景一部分?

注:表达不清←。←


效果如图

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...