Hello i try to create simple sprite that will hold frame animation but i must doing something wrong here
i followed the tutorial from here [[http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Animations]]
the first part . i didn’t do the secound part becouse i didint found any free tool that export to plist but this is another problem .
any way here is my code i invoke it from the bool HelloWorld::init()
but i don’t see any thing in the screen
bool HelloWorld::init()
{
...
...
...
do
{
m_AngelSprite = new AngelSprite();
CC_BREAK_IF(! m_AngelSprite);
m_AngelSprite->setPosition(ccp(m_AngelSprite->getContentSize().width/2,iHeight/2));
this->addChild(m_AngelSprite);
bRet = true;
} while (0);
}
#ifndef __ANGELSPRITE_H__
#define __ANGELSPRITE_H__
#include "cocos2d.h"
class AngelSprite : public cocos2d::CCSprite
{
public :
virtual void draw();
AngelSprite();
//virtual ~AngelSprite(){};
//virtual void draw(void);
void runAnimation();
private:
cocos2d::CCAnimation *animation;
cocos2d::CCAnimate *action;
void playImageAnim();
void loadImgs();
};
#endif
#include "AngelSprite.h"
AngelSprite::AngelSprite()
{
animation = cocos2d::CCAnimation::create();
loadImgs();
playImageAnim();
action = cocos2d::CCAnimate::create(animation);
}
void AngelSprite::draw()
{
//CCSprite::draw();
}
void AngelSprite::loadImgs()
{
for(int i=1;i<=2;i++)
{
char szImageFileName[128] = {0};
sprintf(szImageFileName, "angel_%d.png",i);
animation->addSpriteFrameWithFileName(szImageFileName);
}
}
void AngelSprite::playImageAnim()
{
animation->setDelayPerUnit(0.8f / 2.0f); // This animation contains 14 frames, will continuous 2.8 seconds.
animation->setRestoreOriginalFrame(true); // Return to the 1st frame after the 14th frame is played.
}
void AngelSprite::runAnimation()
{
this->runAction(action); // run action on sprite object
}