精灵表不适用于视网膜显示

时间:2013-05-03 11:01:43

标签: ios6 cocos2d-iphone sprite-sheet

我为sprite sheet创建了一个non retina display,并且它在模拟器上工作正常。 我使用过代码

 -(Void)addSprites{
     [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"image.plist"];

    CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"image.png"];
    [self addChild:spriteSheet];

 // Load up the frames of our animation
    NSMutableArray *walkAnimFrames = [NSMutableArray array];
    for(int i = 1; i < 5; i++) {
        [walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"image%d.png", i]]];
    }

    CCAnimation *walkAnim = [CCAnimation animationWithSpriteFrames:walkAnimFrames delay:0.20f];
// Create a sprite for our bear

    background = [CCSprite spriteWithSpriteFrameName:@"image1.png"];
    background.position = ccp(280, 175);
    self.walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim]];
    [spriteSheet addChild:background];  
}
 -(void)startAnimation{
    [background runAction:_walkAction];

}

对于设备,我已经创建了具有双倍尺寸的视网膜图像和名为image@2x..的图像的精灵表,创建的plistmyplist@2xplist,图像文件为imagefile@2x.png < / p>

我的意思是有4个文件

非视网膜显示

1)imagefile.png(sprite sheet)

2)myPlist.plist

用于Retina显示。

1)imagefile@2x.png(sprite sheet)  每个图像的plist键名也像image@2x.png

2)myPlist@2x.plist

但上面的代码不适用于此代码。我做错了什么或错过了什么?  我的应用程序在设备上崩溃并显示错误消息

 CCSpriteFrameCache: Frame 'image1.png' not found
2013-05-03 16:19:49.764  *** Terminating app due to uncaught exception 
'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object    cannot be nil'

但上面的代码是working fine on simulator

2 个答案:

答案 0 :(得分:2)

默认情况下,cocos2d使用-hd postfix而不是“@ 2x”。精灵表内的文件名必须相同,不能有任何“-hd”或@ 2x。主要的精灵表文件名只需要与后缀“-hd”。

myPlist-hd.plist

答案 1 :(得分:0)

按照给定的步骤 -

  1. 为视网膜和norma分辨率创建两个不同的spritesheets。

  2. 假设你有四张图片image1.png,image2.png,image3.png,image4.png。首先确保它们具有根据视网膜显示的尺寸。然后使用这些图像创建spritesheet和plist。将它们保存为animation@2x.png和animation@2x.plist

  3. 然后获得相同的四个图像将其大小减小到一半。确保他们的名字保持不变。使用zwoptex创建工作表,名称为animation.png和animation.plist。

  4. 现在你有两个不同版本的spritesheets和Plist for retina和normal。使用以下代码加载它们:

    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@“animation.plist”];

    CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"animation.png"];
    [self addChild:spriteSheet];
    

    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@“animation@2x.plist”];

    CCSpriteBatchNode *spriteSheethd = [CCSpriteBatchNode batchNodeWithFile:@"animation@2x.png"];
    [self addChild:spriteSheethd];
    

    现在使用它们。它们会显示正常