2012-10-06 3 views
0

장면 컨트롤러 (상태 관리자) 클래스로 장면을 전환하는 간단한 응용 프로그램을 만드는 연습을하고 있습니다. Dealloc에서 경고합니다.

나는 내 장면 생성 :

+(CCScene *) scene 
{ 
    CCScene *scene = [CCScene node]; 

    GameMenu *layer = [GameMenu node]; 

    [scene addChild: layer]; 

    return scene; 
} 

-(id)init{ 
    if ((self = [super init])){ 
     self.isTouchEnabled = YES; 
     CGSize winSize = [[CCDirector sharedDirector] winSize]; 
     gameMenuLabel = [CCLabelTTF labelWithString:@"This is the Main Menu. Click to Continue" fontName:@"Arial" fontSize:13]; 
     gameMenuLabel.position = ccp(winSize.width/2, winSize.height/1.5); 
     [self addChild:gameMenuLabel]; 
    } 

    return self; 
} 

-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
    NSLog(@"ccTouchesBegan: called from MainMenu object"); 
    [[StateManager sharedStateManager] runSceneWithID:kGamePlay]; 

} 

-(void)dealloc{ 
    [gameMenuLabel release]; 
    gameMenuLabel = nil; 

    [super dealloc]; 
} 

@end 

을하지만이 경고 점점 계속 : https://dl.dropbox.com/u/1885149/Screen%20Shot%202012-10-06%20at%205.23.43%20PM.png (아마 많은 도움을하지만 난 스크린 샷을 링크 할 생각

나는 그것을 함께 할 수있는 뭔가가 생각합니다. 내 장면에서 dealloc을 주석 처리하면 경고 메시지가 표시되지 않습니다. 도움을 주시면 감사하겠습니다.

장면 전환을위한 내 Statemanager의 방법입니다.

-(void)runSceneWithID:(SceneTypes)sceneID { 
    SceneTypes oldScene = currentScene; 
    currentScene = sceneID; 
    id sceneToRun = nil; 
    switch (sceneID) { 
     case kSplashScene: 
      sceneToRun = [SplashScene node]; 
      break; 

     case kGameMenu: 
      sceneToRun = [GameMenu node]; 
      break; 
     case kGamePlay: 
      sceneToRun = [GamePlay node]; 
      break; 
     case kGameOver: 
      sceneToRun = [GameOver node]; 
      break; 

     default: 
      CCLOG(@"Unknown ID, cannot switch scenes"); 
      return; 
      break; 
    } 
    if (sceneToRun == nil) { 
     // Revert back, since no new scene was found 
     currentScene = oldScene; 
     return; 
    }  
    if ([[CCDirector sharedDirector] runningScene] == nil) { 
     [[CCDirector sharedDirector] runWithScene:sceneToRun]; 
    } else { 
     [[CCDirector sharedDirector] replaceScene:sceneToRun]; 
    } 
} 
+1

게시물을 텍스트 형식으로 추가하여 검색 가능하도록해야합니다. –

+0

스크린 샷의 코드는 질문의 코드와 완전히 다릅니다. – jrturton

+0

스크린 샷에 "경고"가 아닌 중단 점이나 충돌이 표시됩니다. – newacct

답변

1

당신은 .... A는이

@property (nonatomic, retain) CCLabelTTF* gameMenuLabel; //in .h file 

처럼 gameMenuLabel에 속성을 유지하고이 쓰기 줘야 대신의

self.gameMenuLabel = [CCLabelTTF labelWithString:@"This is the Main Menu. Click to Continue" fontName:@"Arial" fontSize:13]; 

...

gameMenuLabel = [CCLabelTTF labelWithString:@"This is the Main Menu. Click to Continue" fontName:@"Arial" fontSize:13]; 

문제는 자동으로 해제 된 객체를 gameMenuLabel에 제공 한 다음 다시 릴리스하는 것입니다. 그 객체는 dealloc 섹션에있다. 따라서 충돌.

+0

가능한 경우 ARC로 전환하십시오. Xcode는 이것을 수행 할 수도 있습니다. 편집> 리팩터링 – nielsbot

+0

에서 고마워요! – HelloWorld

+0

답변을 원한다면 언제든지 받아 들일 수 있습니다! :) – mayuur

관련 문제