sub classing CCSpriteBatchNode problem


#1

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 char
path1 = cocos2d::CCFileUtils::sharedFileUtils()>fullPathFromRelativePath;
cache
>addSpriteFramesWithFile(path1);

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


#2

can any one help me to fix this issue


#3

same program i tried in cocos2d in objective c.
it is working there, in cocos2dx in c++ only i am getting this issue

this is my cocos2d code
-(id)initWithColorType:(NSString**)colortype{
NSString** myString =[colortype stringByAppendingString:`".png"];

 if(self =[super initWithFile:myString capacity:8])
 {
 NSString * myString1 =[colortype stringByAppendingString:`“.plist”];

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:myString1];

//self addChild:<#(CCNode )#>
NSMutableArray
animFrames = [NSMutableArray array];
CCSprite* sprite = [CCSprite spriteWithSpriteFrameName:`“right1.png”];

 for (int i = 1; i<=8; ++i)
 {
 CCSpriteFrame *frame1 = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:`“right%d.png”,i]];

[animFrames addObject:frame1];

}

CCAnimation animation = ;
CCAnimate
animate = [CCAnimate actionWithAnimation:animation restoreOriginalFrame:YES];

CCRepeatForever **repeat = ;
;
// ;
;

}
return self ;
}
`end

BubbleSprite * bb=[[BubbleSprite alloc] initWithColorType:`“Rambo”];
;
;
BubbleSprite** bb1=[[BubbleSprite alloc] initWithColorType:@“sick”];

[self addChild:bb1];
[bb1 setPosition:ccp(100, 200)];

can any one help me to create animation class


#4

Now its working
finally i got the solution for this problem
in both plist’s , i used same names for animation frames. Actually we should not use same names in different plist’s.