Error change CCScene

Go To StackoverFlow.com

0

I am beginner in cocos2d, but i have some experience in Objective-C and iphoneSdk. But I have a problem in my application that I can not figure out what the error..

I have a CCLayer (Anime), which shows a little animation to the player, after that it starts another CCLayer (Level):

Anime:

-(id) init{

    if( (self=[super init])) {

CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache]; 
[frameCache addSpriteFramesWithFile:@"Anime.plist"];  



CCSprite * backgound = [CCSprite spriteWithSpriteFrameName:@"Back.png"];
backgound.anchorPoint=ccp(0,0);
[self addChild:backgound z:-1];


CCSprite *body = [CCSprite spriteWithSpriteFrameName:@"Body1.png"];
[self addChild:body z:0];

CCSprite *bMoved = [CCSprite spriteWithSpriteFrameName:@"Gigante1.png"];
[self addChild:bMoved z:1];      


NSMutableArray *nuvemAnim = [[NSMutableArray alloc] init];
        for (int i = 1; i < 41; i++) {
            NSString *frameNames = [NSString stringWithFormat:@"Gigante%i.png",i];
            [nuvemAnim addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] 
                                  spriteFrameByName:frameNames]];

        }    


        CCAnimation *gigAnim = [CCAnimation animationWithFrames:nuvemAnim  delay:1.0f/24.0f];
        CCAnimate* animate = [CCAnimate actionWithAnimation:gigAnim];   


        [bMoved runAction:[CCSequence actions:
                         [CCDelayTime actionWithDuration:1],
                         animate,
                         [CCDelayTime actionWithDuration:1],
                         [CCCallFunc actionWithTarget:self selector:@selector(changeCCScene)],
                           nil]];


    }
return self; 

In Level I use a CCSpriteFrameCache to create the animation of the characters,

Level:

-(id) init{
if( (self=[super init])) {

    self.isTouchEnabled=YES;


    CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache]; 
   [frameCache addSpriteFramesWithFile:@"Level3.plist"]; 

    CCSprite * backgound = [CCSprite spriteWithSpriteFrameName:@"Fundo9.png"];
    backgound.anchorPoint=ccp(0,0);
    [self addChild:backgound z:-1];


    CCSprite man = [CCSprite spriteWithSpriteFrameName:@"Man1.png"];
    [self man z:0];


    eAnim = [[NSMutableArray alloc] init];
    for (int i = 2; i < 178; i++) {
        NSString *frameNames = [NSString stringWithFormat:@Man%i.png",i];
        [eAnim addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] 
                                spriteFrameByName:frameNames]];

    } 

but gives me this type of error in console infinitely for all frames

2012-04-03 23:37:51.987 GigV1[1432:10a03] cocos2d: WARNING: an alias with name Man12.png already exists
2012-04-03 23:37:51.988 GigV1[1432:10a03] cocos2d: WARNING: an alias with name Man155.png already exists

ANy ideai why this happen??

Thanks

2012-04-03 23:04
by DaSilva


1

You are loading sprite frames from Anime.plist and Level3.plist:

CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache]; 
[frameCache addSpriteFramesWithFile:@"Anime.plist"]; 

[frameCache addSpriteFramesWithFile:@"Level3.plist"]; 

This warning indicates that you are adding more sprite frames with the same name:

WARNING: an alias with name Man12.png already exists

To resolve this you have three options:

  1. make sure you don't use the same sprite frame name (the same image) in two different texture atlases
  2. unload the sprite frames from the cache that you don't need before loading the sprite frames from another texture atlas
  3. ignore the warnings
2012-04-04 10:00
by LearnCocos2D
I could solve my problem ...I was using the Level's method "OnEnter# that was creating another class of itself, and so the successive errors ..

Thank - DaSilva 2012-04-04 22:34



1

You are missing quotes in this line:

NSString *frameNames = [NSString stringWithFormat:@Man%i.png",i];

Should be an opening quote after the @ and before the Man%i

2012-04-04 01:35
by johnbakers
It was a error in "copy" the code... Sorry.. but thanks anyway. - DaSilva 2012-04-04 22:35