2013-04-15 3 views
0

제대로 작동하지 않을 수 있기 때문에 cocos2d에서 현재 장면을 다시 시작하는 적절한 방법이 무엇일까 궁금합니다. ....cocos2d에서 현재 장면 다시 시작

CCScene *currentScene = [CCDirector sharedDirector].runningScene; 
CCScene *newScene = [[[currentScene class] alloc] init]; 

[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:0.7f scene:newScene]]; 

주 나는 실제 장면을 다시 시작하려면 다음 코드를 사용하고 있지만 검은 화면이 나타납니다 :이 사실을 함께 할 수있는 뭔가를 (내가 알아 맞추기)가 알고하지는 이 코드는 일시 중지 메뉴 및 항목을 관리하는 CClayer 하위 클래스에서 실행됩니다.

주 2 : 이것은 일반적인 다시 시작이며 모든 장면에서 작동하도록 가장하므로 감사합니다.

+0

메모리 누수 또는 개체 덮어 쓰기 검사 (좀비 사용 가능) – LearnCocos2D

+0

메모리 누수 또는 과도한 개체가없고 방금 문제를 발견했습니다. [currentScene class]는 사용자 지정 클래스 이름 대신 CCScene을 반환합니다. 그게 내가 왜 검은 화면을 보는지. – Potajedehabichuelas

답변

2

, 이것이 내가 문제를 극복 할 수있는 방법은 다음과 같습니다 nameOfClass이 이름을 포함하는 문자열입니다

Class SceneClass = NSClassFromString(nameOfClass); 
[[CCDirector sharedDirector]replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[SceneClass scene]]]; 

다시 시작할 장면을 구현하는 클래스의 이 방법은 매력처럼 작동하며 .h 파일을 #import하지 않아도됩니다.

1

수동 할당과 관련이 있다고 가정합니다. 대부분의 경우 cocos2d 정적 생성자를 호출하여 메모리 관리를 처리하도록하는 것이 좋습니다. 이것은 내가하는 일입니다 .-

MyClassScene *newScene = [MyClassScene node]; 
[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:kTransitionTime scene:newScene withColor:ccc3(255, 255, 255)]]; 

희망이 있습니다.

+0

고마워,하지만 똑같은 결과가 난다. 여기에있는 것은 일반적인 재시작이며 모든 장면에서 작동하도록하는 척하기 때문에 CCScene * currentScene = [CCDirector sharedDirector] .runningScene; 현재 어떤 장면이 실행 중인지 알고 싶습니다. – Potajedehabichuelas

+0

음. 이해합니다. 콘솔에 오류가 있습니까? – ssantos

+0

아니요, 전혀 아닙니다! – Potajedehabichuelas

0

이 시도 :

같은 문제가 발생하는 다른 사람에 대한
CCScene *currentScene = [[CCDirector sharedDirector] runningScene]; 

[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:0.7f scene:[currentScene node]]]; 
+0

[CCScene node]가 경고를 생성하고 앱이 충돌합니다. 이유 : '- [CCScene node] : 인식 할 수없는 선택기 – Potajedehabichuelas

관련 문제