Ios 更改场景时出错

Ios 更改场景时出错,ios,ipad,ios5,cocos2d-iphone,Ios,Ipad,Ios5,Cocos2d Iphone,我是cocos2d的初学者,但我在Objective-C和iphoneSdk方面有一些经验。 但是我的应用程序中有一个问题,我无法找出错误所在 我有一个CCLayer(动画),它向玩家显示了一点动画,然后开始另一个CCLayer(关卡): 动画: -(id) init{ if( (self=[super init])) { CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache]; [f

我是cocos2d的初学者,但我在Objective-C和iphoneSdk方面有一些经验。 但是我的应用程序中有一个问题,我无法找出错误所在

我有一个CCLayer(动画),它向玩家显示了一点动画,然后开始另一个CCLayer(关卡):

动画:

-(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; 
你知道为什么会这样吗


谢谢

您在这一行中缺少引号:

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


应该是
@
之后和
人%i

之前的开场白,您正在从Anime.plist和Level3.plist加载精灵帧:

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

[frameCache addSpriteFramesWithFile:@"Level3.plist"]; 
此警告表示您正在添加更多同名的精灵帧:

WARNING: an alias with name Man12.png already exists
要解决此问题,您有三个选项:

  • 确保在两个不同的纹理地图集中不使用相同的精灵帧名称(相同的图像)
  • 从缓存中卸载不需要的精灵帧,然后再从其他纹理图集加载精灵帧
  • 忽略这些警告

  • 我可以解决我的问题…我使用了Level的方法“OnEnter”,它创建了自己的另一个类,因此出现了连续的错误。。谢谢
    CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache]; 
    [frameCache addSpriteFramesWithFile:@"Anime.plist"]; 
    
    [frameCache addSpriteFramesWithFile:@"Level3.plist"]; 
    
    WARNING: an alias with name Man12.png already exists