0

我是 cocos2d 的初学者,但我在 Objective-C 和 iphoneSdk 方面有一些经验。但是我的应用程序中有一个问题,我无法弄清楚错误是什么..

我有一个 CCLayer (Anime),它向玩家显示一个小动画,然后它启动另一个 CCLayer (Level):

日本动画片:

-(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; 

在 Level I 中,使用 CCSpriteFrameCache 来创建角色的动画,

等级:

-(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]];

    } 

但在控制台中给我这种类型的错误对于所有帧都无限

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

任何想法为什么会发生这种情况?

谢谢

4

2 回答 2

1

您在此行中缺少引号:

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

应该是在之后@和之前的开场报价Man%i

于 2012-04-04T01:35:22.990 回答
1

您正在从 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

要解决此问题,您有三个选择:

  1. 确保不要在两个不同的纹理图集中使用相同的精灵帧名称(相同的图像)
  2. 在从另一个纹理图集加载精灵帧之前,从缓存中卸载不需要的精灵帧
  3. 忽略警告
于 2012-04-04T10:00:09.383 回答