我正在尝试在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 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的其他图像的纹理。
这是我的英雄子类中的初始化:
-(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;
}
如果我不清楚,请原谅我,所以让我知道我需要提供的任何其他信息。现在发布这个因为我不知道还有什么地方可以解决它以及我应该提供什么其他信息,而且其他一些cocos开发者可能很明显我发布的内容有什么不对。感谢
答案 0 :(得分:0)
模拟器可以比设备更宽容。仔细检查您的文件名是否真的是“heroTestSheet.png”而不是“HeroTestSheet.png”。它在您的设备上区分大小写。
答案 1 :(得分:0)
想出来..它只是它试图使用的heroTestSheet.png在某种程度上无效。我在一个较旧的Photoshop中导出,但我不是很肯定它有什么设置。我从一个没有任何颜色管理设置的新版Photoshop再次导出它,现在它工作正常!
答案 2 :(得分:0)
我认为您的图像未添加到项目中。
您必须将二进制文件复制到资源。
选择目标,然后选择构建阶段,然后复制捆绑资源 在你的内容上添加你的图像。
我认为它会奏效。