아이폰 개발 팁 - cocos2d 로딩화면 쓰레드 로딩하기

쓰레드를 이용해서 자연스러운 로딩화면을 보여주면서 

백그라운드로 로딩하는데는 여러가지 방법이 있겠지만,

cocos2d 에서 이용할 수 있는 간단한 방법 중엔 이런게 있네요.

원문 링크 중의 어느 댓글을 참고해서 테스트를 해보면..



- (void) applicationDidFinishLaunching:(UIApplication*)application

{

.....


// app뜨면 바로 로딩씬을 불러와서 실행~

loadingScene = [[LoadingScene alloc] init];

[[CCDirector sharedDirector] runWithScene: loadingScene];


// 쓰레드 생성해서 로딩하기~

NSThread* thread = [[[NSThread alloc] initWithTarget:self selector:@selector(loadingProc) object:nil] autorelease];

[thread start];

}


- (void)loadingSceneProc {

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];


// 이게 핵심 코드 없으면 텍스쳐 다 깨지고 난리납니다;

// 뭐하자는 얘기인지 감만 올 뿐이죠 =_=;;

EAGLContext *k_context = [[[EAGLContext alloc]

   initWithAPI :kEAGLRenderingAPIOpenGLES1

   sharegroup:[[[[CCDirector sharedDirector] openGLView] context] sharegroup]] autorelease];

[EAGLContext setCurrentContext:k_context];

// 여기서 필요한 것들을 백그라운드로 로딩!

// 실제로 사용할 MainScene에 로딩할게 잔뜩있다고 치고.. 생성해서 로딩~

mainScene = [[MainScene alloc] init];


// 이게 혹시(!) thread-safe하지 않으면 다른 방식으로 notification 처리 필요~

[[CCDirector sharedDirector] replaceScene:mainScene];

[pool release];

}



이 글과 관련있는 글을 자동검색한 결과입니다 [?]

by 쉬귀 | 2010/10/31 03:03 | 개발 | 트랙백 | 덧글(1)

트랙백 주소 : http://www.suigui.com/tb/3053267
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
Commented by 엘슈나이더 at 2011/09/22 12:54
개발 팁 감사합니다.
제 블러그에 개시해도 되나요?

:         :

:

비공개 덧글

◀ 이전 페이지 다음 페이지 ▶