我對Objective-C比較陌生,我開始經歷SneakyInput。我將它添加到了我正在製作的小應用程序(它啓用了ARC),並且當我運行該應用程序時它剛剛崩潰。我再次嘗試,編寫針對非ARC的鬼祟輸入,並且完美地工作。SneakyInput在ARC上的問題
這是ARC版本(其中已啓用ARC),它崩潰
- (void)initJoystick
{
SneakyJoystickSkinnedBase *joystickBase;
joystickBase.backgroundSprite = [CCSprite spriteWithFile:@"[email protected]"];
joystickBase.thumbSprite = [CCSprite spriteWithFile:@"Icon-Small.png"];
joystickBase.joystick = [[SneakyJoystick alloc] initWithRect: CGRectMake(0, 0, 128, 128)];
joystickBase.position = ccp(55, 55);
[self addChild:joystickBase];
}
- (id)init
{
if((self=[super init]))
{
[self initJoystick];
}
return self;
}
@end
這是不ARC版本,它不會崩潰
- (void)initJoystick
{
SneakyJoystickSkinnedBase *joystickBase = [[[SneakyJoystickSkinnedBase alloc] init] autorelease];
joystickBase.backgroundSprite = [CCSprite spriteWithFile:@"[email protected]"];
joystickBase.thumbSprite = [CCSprite spriteWithFile:@"Icon-Small.png"];
joystickBase.joystick = [[SneakyJoystick alloc] initWithRect: CGRectMake(0, 0, 128, 128)];
joystickBase.position = ccp(55, 55);
[self addChild:joystickBase];
leftJoystick = [joystickBase.joystick retain];
}
-(id) init
{
if((self=[super init]))
{
[self initJoystick];
}
return self;
}
@end
我想繼續在ARC與應用程序的其餘部分,所以我想知道是否有人可以告訴我如何解決這個問題,以便它不會崩潰。對不起,如果非常noobie問題。
這是錯誤消息時ARC啓用
2013-06-29 20:49:15.724 joystick[2135:12c03] *** Assertion failure in -[HelloWorldLayer addChild:],
/Users/monagros/Desktop/Stuff/Cocos2D/apps/joystick/joystick/libs/cocos2d/CCNode.m:362
這些每個文件的編譯器標誌可能已經設置,因爲應用程序編譯和運行,只是遇到一個實際上並非ARC相關的運行時異常。 –
我明白了,把它當作暗示:) – chrs