sprite sheet不工作的视网膜显示 [英] sprite sheet not working for retina display
问题描述
我为非视网膜显示
创建了 sprite sheet
,并在模拟器上工作罚款
我使用了代码
- (Void)addSprites {
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@image .plist];
CCSpriteBatchNode * spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@image.png];
[self addChild:spriteSheet];
//加载我们动画的帧
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];
//为我们的熊创建一个sprite
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图像,命名为 image @ 2x ..
的图像。创建的 plist
code> myplist @ 2xplist 和图片文件 imagefile@2x.png
我的意思是有4个文件
用于非视网膜显示。
1) imagefile.png(sprite sheet)
2) myPlist.plist
c $ c> imagefile@2x.png(sprite sheet)
每个图像的plist键名也像image@2x.png
2) myPlist@2x.plist
,但上述代码不适用于此代码。我做错了或丢失的东西?
我的应用在设备上崩溃,显示错误消息
CCSpriteFrameCache:未找到框架'image1.png'
2013-05-03 16:19:49.764 ***由于未捕获异常而终止应用程序
'NSInvalidArgumentException',原因:'*** - [__ NSArrayM insertObject:atIndex:]:object不能为nil'
但上述代码是在模拟器上正常工作
p>
默认情况下cocos2d使用-hd后缀而不是@ 2x。并且sprite表内的文件名需要是相同的,没有任何-hd或@ 2x。只有主sprite表文件名需要使用后缀-hd。
myPlist-hd.plist
I have create a sprite sheet
for non retina display
and its working fine on simulator..
I have used the code
-(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];
}
And for for device i have created sprite sheet with retina image with double size and image named like image@2x..
the created plist
is myplist@2xplist
and image file is imagefile@2x.png
I mean there are 4 files
for non retina display.
1) imagefile.png(sprite sheet)
2) myPlist.plist
for Retina display.
1) imagefile@2x.png(sprite sheet)
the plist key name for every image is also like image@2x.png
2) myPlist@2x.plist
but the above code is not working for this code. m i doing something wrong or missing somthing? my app crash on device with error message
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'
but the above code is working fine on simulator
By default cocos2d use -hd postfix not "@2x". And file names inside the sprite sheet need to be same without any "-hd" or @2x. Just the main sprite sheet file name need to be with postfix "-hd".
myPlist-hd.plist
这篇关于sprite sheet不工作的视网膜显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!