cocos2d how to combine sprites

Go To StackoverFlow.com

1

I want to combine three sprites and display it as a single sprite. I created a empty sprite and added parts but doesn't work properly.

    CCNode *stars = [CCNode node];

    CCSprite *star1 = [CCSprite spriteWithSpriteFrameName:@"star.png"];
    star1.position = ccp(-10, 0);
    [stars addChild:star1];

    CCSprite *star2 = [CCSprite spriteWithSpriteFrameName:@"star.png"];
    star2.position = ccp(0, 0);
    [stars addChild:star2];

    CCSprite *star3 = [CCSprite spriteWithSpriteFrameName:@"star.png"];
    star3.position = ccp(10, 0);
    [stars addChild:star3];

    [self addChild:stars];

and I got the following exception

erminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid spriteFrameName: star.png'

please help me to figure out.

2012-04-04 07:26
by Hassy31
what is sprites - tams 2012-04-04 07:32
sorry..that was a mistake - Hassy31 2012-04-04 07:42


1

Are you adding the single sprite like this:

CCSprite *star1 = [CCSprite **spriteWithFile**:@"star.png"];
star1.position = ccp(-10, 0);
[self addChild:star1];

It sounds to me like you are trying to use sprite frames but you haven't loaded any sprite sheets properly or you mean to use spriteWithFile.

CCNode *stars = [CCNode node];

CCSprite *star1 = [CCSprite spriteWithFile:@"star.png"];
star1.position = ccp(-10, 0);
[stars addChild:star1];

CCSprite *star2 = [CCSprite spriteWithFile:@"star.png"];
star2.position = ccp(0, 0);
[stars addChild:star2];

CCSprite *star3 = [CCSprite spriteWithFile:@"star.png"];
star3.position = ccp(10, 0);
[stars addChild:star3];

[self addChild:stars];
2012-04-04 08:14
by James Webster
works perfectly.thank you very much - Hassy31 2012-04-04 08:19


0

It sounds like there is something wrong with the .png file. Make sure that you have added it to the resources for your project.

2012-04-04 07:33
by tams
thank you for the reply.I have added the star.png file in to Resources and I can display it as a normal sprite - Hassy31 2012-04-04 07:41
Ads