2013-05-03 110 views
0

工作我已創建爲non retina display一個sprite sheet及其對模擬器工作正常.. 我已經使用了代碼精靈表不是視網膜顯示

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

}

以及用於設備我已經建立sprite sheet with retina image with double size and image named like [email protected] the created plist is [email protected] and image file is [email protected]

我的意思是有4個文件

非視網膜顯示。

1)imagefile.png(sprite sheet)

2)myPlist.plist

爲Retina顯示。

1)[email protected](sprite sheet) 每個圖像plist中關鍵名也像[email protected]

2)[email protected]

但上面的代碼不工作的此代碼。我做錯了什麼或缺少什麼? 設備上我的應用程序崩潰,錯誤消息

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

默認情況下使用的cocos2d後綴-HD不是「@ 2X」。並且精靈表內的文件名稱必須相同,而沒有任何「-hd」或@ 2x。只有主精靈表單文件名需要用後綴「-hd」。

myPlist-hd.plist

0

按照給定的步驟 -

  1. 創建兩個視網膜和諾瑪分辨率兩種不同的spritesheets。

  2. 假設您有四張圖片image1.png,image2.png,image3.png,image4.png。首先確保它們的尺寸根據視網膜顯示。然後使用這些圖像創建spritesheet和plist。將它們保存爲[email protected][email protected]

  3. 然後獲取相同的四張圖像將其大小縮小爲一半。確保他們的名字保持不變。使用名稱爲animation.png和animation.plist的zwoptex創建表單。

現在你有兩個不同版本的spritesheets和Plist視網膜和正常。使用以下代碼加載它們:

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@「animation。plist中 「];

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

[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@」 [email protected]「];

CCSpriteBatchNode *spriteSheethd = [CCSpriteBatchNode batchNodeWithFile:@"[email protected]"]; 
[self addChild:spriteSheethd]; 

現在使用的話,他們將顯示效果細膩

+0

我們需要。寫同樣的代碼兩次? – KsK 2013-05-06 04:12:23

+0

此代碼也顯示模擬器上的高清圖像 – KsK 2013-05-06 04:26:59