iphone - 需要帮助解决简单的 cocos2d 错误

标签 iphone cocos2d-iphone

我正在使用以下代码在屏幕上渲染图像

-(id) init
{
    if( (self=[super init] )) {
        CGSize winSize = [[CCDirector sharedDirector] winSize];
        CCSprite *player = [CCSprite spriteWithFile:@"Player.png" rect:CGRectMake(0, 0, 27, 40)];
        player.position = ccp(player.contentSize.width/2, winSize.height/2);
        [self addChild:player];     
    }
    return self;
}

当我运行代码时出现以下错误

continue
2011-07-11 19:25:58.220 testcellapp[441:707] cocos2d: cocos2d v1.0.0-rc3
2011-07-11 19:25:58.229 testcellapp[441:707] cocos2d: Using Director Type:CCDirectorDisplayLink
2011-07-11 19:25:58.407 testcellapp[441:707] cocos2d: OS version: 4.3.1 (0x04030100)
2011-07-11 19:25:58.411 testcellapp[441:707] cocos2d: GL_VENDOR:   Imagination         Technologies
2011-07-11 19:25:58.415 testcellapp[441:707] cocos2d: GL_RENDERER: PowerVR SGX 535
2011-07-11 19:25:58.418 testcellapp[441:707] cocos2d: GL_VERSION:  OpenGL ES-CM 1.1       IMGSGX535-58.6
2011-07-11 19:25:58.423 testcellapp[441:707] cocos2d: GL_MAX_TEXTURE_SIZE: 2048
2011-07-11 19:25:58.427 testcellapp[441:707] cocos2d: GL_MAX_MODELVIEW_STACK_DEPTH: 16
2011-07-11 19:25:58.430 testcellapp[441:707] cocos2d: GL_MAX_SAMPLES: 4
2011-07-11 19:25:58.434 testcellapp[441:707] cocos2d: GL supports PVRTC: YES
2011-07-11 19:25:58.437 testcellapp[441:707] cocos2d: GL supports BGRA8888 textures: YES
2011-07-11 19:25:58.441 testcellapp[441:707] cocos2d: GL supports NPOT textures: YES
2011-07-11 19:25:58.444 testcellapp[441:707] cocos2d: GL supports discard_framebuffer: YES
2011-07-11 19:25:58.447 testcellapp[441:707] cocos2d: compiled with NPOT support: NO
2011-07-11 19:25:58.450 testcellapp[441:707] cocos2d: compiled with VBO support in TextureAtlas : NO
2011-07-11 19:25:58.454 testcellapp[441:707] cocos2d: compiled with Affine Matrix transformation in CCNode : YES
2011-07-11 19:25:58.457 testcellapp[441:707] cocos2d: compiled with Profiling Support: NO
2011-07-11 19:25:58.554 testcellapp[441:707] cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
2011-07-11 19:25:58.558 testcellapp[441:707] cocos2d: Couldn't add image:Player.png in CCTextureCache
2011-07-11 19:25:58.564 testcellapp[441:707] *** Assertion failure in -[HelloWorldLayer addChild:], /Users/shahbazali/Documents/testcellapp/libs/cocos2d/CCNode.m:408
2011-07-11 19:25:58.601 testcellapp[441:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Argument must be non-nil'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x32c3064f __exceptionPreprocess + 114
    1   libobjc.A.dylib                     0x31da4c5d objc_exception_throw + 24
    2   CoreFoundation                      0x32c30491 +[NSException raise:format:arguments:] + 68
    3   Foundation                          0x318a2573 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 62
    4   testcellapp                         0x00067c1c -[CCNode addChild:] + 196
    5   testcellapp                         0x000033ec -[HelloWorldLayer init] + 400
    6   testcellapp                         0x00066ca0 +[CCNode node] + 76
    7   testcellapp                         0x000031fc +[HelloWorldLayer scene] + 100
    8   testcellapp                         0x00002aac -[testcellappAppDelegate applicationDidFinishLaunching:] + 1028
    9   UIKit                               0x32f6a85d -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 832
    10  UIKit                               0x32f64b65 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 272
    11  UIKit                               0x32f397d7 -[UIApplication handleEvent:withNewEvent:] + 1114
    12  UIKit                               0x32f39215 -[UIApplication sendEvent:] + 44
    13  UIKit                               0x32f38c53 _UIApplicationHandleEvent + 5090
    14  GraphicsServices                    0x31118e77 PurpleEventCallback + 666
    15  CoreFoundation                      0x32c07a97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
    16  CoreFoundation                      0x32c0983f __CFRunLoopDoSource1 + 166
    17  CoreFound

请帮忙解释为什么会出现此错误

最佳答案

[CCNode addChild:] 使用 NSAssert 让您知道参数不允许为 nil。 确保 player 不为零。

另请注意崩溃前日志中的行。

cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
cocos2d: Couldn't add image:Player.png in CCTextureCache

关于iphone - 需要帮助解决简单的 cocos2d 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6651699/

相关文章:

iphone - 从 native iOS Objective-C 应用程序与 Python 或 Java 通信?

iphone - 如何删除 TableView Controller 中的行(Three20)

iphone - [iOS]如何将当前 View 的状态设为 "snapshot"

ios - 以编程方式调用 textFieldShouldReturn

iphone - 在 Game Center 上验证本地用户时出现延迟

iphone - 想要针对不同的 iPhone 界面方向使用多个 Nib

iPhone 和 iPad - 两个图标和两个 plist?

cocos2d-iphone - 使用 cocos2d-iphone 启用 2D 投影的充分理由是什么?

objective-c - 如何在 cocos2d 中启用多点触控?

iphone - arc4random 抛出大量数字