hi
in my project i am creating sequence of animation.
for that i created separate class for animation loading which is
sub class of CCSpriteBatchNode.
in the animation class, i am trying to load sequence of frames based on the
spritesheet and .plist files and and to render animation sequence.
my code is
spriteClass.h
………………
#include “cocos2d.h”
class spriteClass:public cocos2d::CCSpriteBatchNode
{
public:
spriteClass();
virtual bool initWithFile(const char * fileName);
void animationState(const char * fileName);
};
spriteClass.cpp
………………………
#include “spriteClass.h”
spriteClass::spriteClass()
{
}
bool spriteClass::initWithFile(const char * fileName)
{
const std::string fileName1= fileName+ std::string(“.png”);
const char * fileName2=fileName1.c_str();
if(CCSpriteBatchNode::initWithFile(fileName2,8))
{
animationState(fileName);
}
return true;
}
void spriteClass::animationState(const char * fileName){
const std::string fileName1= fileName+ std::string(“.plist”);
fileName=fileName1.c_str();
cocos2d::CCSpriteFrameCache cache = cocos2d::CCSpriteFrameCache::sharedSpriteFrameCache;
const charpath1 = cocos2d::CCFileUtils::sharedFileUtils()>fullPathFromRelativePath;>addSpriteFramesWithFile(path1);
cache
cocos2d::CCSprite* sprite = cocos2d::CCSprite::createWithSpriteFrameName(“left1.png”);
contentSize=sprite~~>getContentSize;
cocos2d::CCArray* animFrames = cocos2d::CCArray::createWithCapacity;
char str[100] = ;
for
{
sprintf);
cocos2d::CCSpriteFrame **frame = cache~~>spriteFrameByName;
cocos2d::CCSize xooo1= frame~~>getOriginalSize;
animFrames~~>addObject;
}
cocos2d:: CCAnimation *animation = cocos2d::CCAnimation::createWithSpriteFrames;
sprite~~>runAction ));
CCSpriteBatchNode::addChild; ///////////
}
and i am creating objects for spriteClass in HelloWorldScene.cpp
spriteClass** spriteSheet= new spriteClass;
spriteSheet~~>initWithFile(“Rambo”); //Rambo.png
spriteSheet~~>setTag;
spriteSheet~~>setPosition(ccp(100,100));
//addChild(spriteSheet);
this~~>addChild;
spriteClass * spriteSheet1= new spriteClass;
spriteSheet1~~>initWithFile(“sick”); //sick.png
spriteSheet1~~>setTag;
spriteSheet1~~>setPosition(ccp(100,200));
//float X= spriteSheet1~~>getContentSize.height;
//addChild;
this~~>addChild(spriteSheet1);
here my problem is if i am loading one image/animation files(Rambo.png or sick.png) its working fine
if i am loading two images/animation files (Rambo.png and sick.png) its throwning error
is it right way to create separate class for creating animation or is there any other
way to create animation class
Thanks in advance