2011-07-11 73 views
2

需要幫助我使用下面的代碼在屏幕上顯示在解決簡單的cocos2d錯誤

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

請幫助爲什麼這個錯誤即將到來

回答

5

[CCNode addChild:]使用NSAssert讓你知道該參數不允許爲零。 確保player不是零。

還要注意崩潰前日誌中的行。

cocos2d:CCTexture2D。 無法創建紋理。 UIImage的是零
的cocos2d:在CCTextureCache

Player.png: 無法添加圖片