Cocos2D立即在iPhone上崩溃,但不在模拟器中
我正试图在iPhone上测试Cocos2D应用程序,并从控制台复制此崩溃:Cocos2D立即在iPhone上崩溃,但不在模拟器中,iphone,crash,cocos2d-iphone,sprite,Iphone,Crash,Cocos2d Iphone,Sprite,我正试图在iPhone上测试Cocos2D应用程序,并从控制台复制此崩溃: cocos2d: CCSpriteFrameCache: Trying to use file 'heroTestSheet.png' as texture cocos2d: CCTexture2D. Can't create Texture. UIImage is nil cocos2d: Couldn't add image:heroTestSheet.png in CCTextureCach
cocos2d: CCSpriteFrameCache: Trying to use file 'heroTestSheet.png' as texture
cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
cocos2d: Couldn't add image:heroTestSheet.png in CCTextureCache
cocos2d: CCSpriteFrameCache: Couldn't load texture
cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
cocos2d: Couldn't add image:heroTestSheet.png in CCTextureCache
cocos2d: CCSpriteFrameCache: Frame 'heroFrame1.png' not found
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableArray insertObject:atIndex:]: attempt to insert nil object at 0'
*** Call stack at first throw:
(
0 CoreFoundation 0x3759dc7b __exceptionPreprocess + 114
1 libobjc.A.dylib 0x32d9bee8 objc_exception_throw + 40
2 CoreFoundation 0x3752a951 -[__NSArrayM insertObject:atIndex:] + 136
3 CoreFoundation 0x3752a8bf -[__NSArrayM addObject:] + 34
4 cocosTests 0x0000ce28 -[HeroClass init] + 1544
5 cocosTests 0x0000304c -[DebugZoneLayer init] + 860
6 cocosTests 0x00074e04 +[CCNode node] + 76
7 cocosTests 0x0000c4e4 -[DebugZoneScene init] + 244
8 cocosTests 0x00074e04 +[CCNode node] + 76
9 cocosTests 0x0000c390 +[DebugZoneScene scene] + 100
10 cocosTests 0x00002540 -[cocosTestsAppDelegate applicationDidFinishLaunching:] + 1028
11 UIKit 0x3592502c -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1200
12 UIKit 0x3591ea78 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 396
13 UIKit 0x358d82e4 -[UIApplication handleEvent:withNewEvent:] + 1476
14 UIKit 0x358d7b1c -[UIApplication sendEvent:] + 68
15 UIKit 0x358d73b4 _UIApplicationHandleEvent + 6824
16 GraphicsServices 0x33e77c88 PurpleEventCallback + 1048
17 CoreFoundation 0x3752f5cb __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 28
18 CoreFoundation 0x3752f589 __CFRunLoopDoSource1 + 164
19 CoreFoundation 0x37521835 __CFRunLoopRun + 580
20 CoreFoundation 0x3752150b CFRunLoopRunSpecific + 226
21 CoreFoundation 0x37521419 CFRunLoopRunInMode + 60
22 UIKit 0x3591d554 -[UIApplication _run] + 548
23 UIKit 0x3591a558 UIApplicationMain + 972
24 cocosTests 0x000020c4 main + 100
25 cocosTests 0x0000205c start + 40
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
在模拟器中运行它运行得很好,但是当它启动时,我仍然在控制台中收到这样一条消息“CCSpriteFrameCache:尝试使用文件'heroTestSheet.png'作为纹理””
我想这就是问题的根源。也许我只是理解我的英雄精灵子类的代码应该如何编写。我认为heroTestSheet.png是它用来分割成其他引用plist的图像的纹理
这是我的英雄子类中的init:
-(id) init{
self = [super init];
if (!self) {
return nil;
}
_collisWidthFromCtr = 16;
_collisHeightFromCtr = 16;
_collisPushPointsNums = 5;
_travelRectCenterPoints = [[NSMutableArray alloc] init];
_collisPushPoints = [[NSMutableArray alloc] init];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( _collisWidthFromCtr, _collisHeightFromCtr)] atIndex:0];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( _collisWidthFromCtr, 0)] atIndex:1];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( _collisWidthFromCtr,-_collisHeightFromCtr)] atIndex:2];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( 0, _collisHeightFromCtr)] atIndex:3];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake(-_collisWidthFromCtr, _collisHeightFromCtr)] atIndex:4];
_rectCheckRes = 32;
_speed = 8;
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"heroTestSheet.plist"];
_heroSpriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"heroTestSheet.png"];
//[self addChild:_heroSpriteSheet];
NSMutableArray *heroSpriteFlyAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 2; ++i) {
[heroSpriteFlyAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"heroFrame%d.png", i]]];
}
CCAnimation *heroSpriteFlyAnim = [CCAnimation animationWithFrames:heroSpriteFlyAnimFrames delay:0.03f];
_heroSprite = [CCSprite spriteWithSpriteFrameName:@"heroFrame1.png"];
_heroSpriteFlyAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:heroSpriteFlyAnim restoreOriginalFrame:NO]];
[_heroSprite runAction:_heroSpriteFlyAction];
[_heroSpriteSheet addChild:_heroSprite];
return self;
}
-(id)init{
self=[super init];
如果(!self){
返回零;
}
_collisWidthFromCtr=16;
_collisHeightFromCtr=16;
_碰撞点SNUMS=5;
_travelRectCenterPoints=[[NSMutableArray alloc]init];
_collisPushPoints=[[NSMutableArray alloc]init];
[\u collishpoints insertObject:[NSValue-valueWithCGPoint:CGPointMake(\u collisswidthfromctr,\u collisHeightFromCtr)]索引:0];
[\u collisPushPoints insertObject:[NSValue-valueWithCGPoint:CGPointMake(\u collisWidthFromCtr,0)]索引:1];
[\u collishpoints insertObject:[NSValue-valueWithCGPoint:CGPointMake(\u collisswidthfromctr,-\u collisHeightFromCtr)]索引:2];
[\u collishpoints insertObject:[NSValue-valueWithCGPoint:CGPointMake(0,\u collisHeightFromCtr)]索引:3];
[\u collishpoints insertObject:[NSValue-valueWithCGPoint:CGPointMake(-u collisswidthfromctr,\u collisHeightFromCtr)]索引:4];
_rectCheckRes=32;
_速度=8;
[[CCSpriteFrameCache sharedSpriteFrameCache]addSpriteFramesWithFile:@“heroTestSheet.plist”];
_heroSpriteSheet=[CCSpriteBatchNode batchNodeWithFile:@“heroTestSheet.png”];
//[self addChild:_herospitesheet];
NSMutableArray*heroSpriteFlyAnimFrames=[NSMutableArray];
对于(int i=1;i模拟器可以比设备更宽容。请仔细检查您的文件名是否为“heroTestSheet.png”而不是“heroTestSheet.png”例如,它在您的设备上区分大小写。找到了它。它只是尝试使用的heroTestSheet.png在某种程度上无效。我在旧的photoshop中导出,但我不确定它有什么设置。我从新的photoshop中再次导出它,没有任何颜色管理设置,现在它工作正常!我想您的图像未添加到项目中
您必须将二进制文件复制到资源
选择目标,然后选择构建阶段,然后复制捆绑资源
在该内容上添加您的图像
我认为它会起作用。是的,我听说这有时可能是这些问题的原因,但情况完全一样。我只是想让你知道,HerosriteSheet是在头界面中设置的,就像CCSpriteBatchNode*\U HerosriteSheet;属性是像@property(非原子,保留)CCSpriteBatchNode*HerosriteSheet;并在.m中合成,就像@Synthetic HerosriteSheet=\u HerosriteSheet;为什么有“@Synthetic HerosriteSheet=\u HerosriteSheet;”而不是“@Synthetic HerosriteSheet;”不重要:)无论如何,您也可以尝试将编译器从“LLVM”更改为“GCC 4.2”或者别的什么…哦,另一件事。你的spritesheet有多大?我想它不超过1000*1000像素?我相信iPhone3G的限制是1000*1000,而iPhone4的限制是2000*2000或者别的什么。好吧,现在我没有主意了。试着删除文件,然后清理,然后再将其添加到你的项目中。你可以尝试在cocos2d论坛上提问。。。您使用什么版本的cocos2d?