cocos2D를 설치하고 cocos2D Template만을 적용해서 생성되는 Hello World 구현과정을 살펴보자.
기본으로 생성되는 프로젝트는 다음과 같이 구성된다.
ㄱ. applicationDidFinishLaunching() 함수에서 직접호출
주요 프로세스 확인하기
1. main 함수(Other Sources/main.m)
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
// 사용자정의 Delegate호출
int retVal = UIApplicationMain(argc, argv, nil, @"_MyGameAppDelegate");
[pool release];
return retVal;
}
2. _MyGameAppDelegate::applicationDidFinishLaunching()함수
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
// CC_DIRECTOR_INIT()
//
// 1. Initializes an EAGLView with 0-bit depth format, and RGB565 render buffer
// 1. OpenGL ES 화면을 depth buffer를 사용하지 않고, 화면은 16bit color(565) 방식으로 세팅
// 2. EAGLView multiple touches: disabled
// 2. 멀티터치는 사용하지 않음
// 3. creates a UIWindow, and assign it to the "window" var (it must already be declared)
// 3. UIWindow를 생성하고 "window"변수에 연결
// 4. Parents EAGLView to the newly created window
// 4. OpenGL ES구현 뷰인 UIWindow를 새로생성된 window에 연결생
// 5. Creates Display Link Director
// 5. Display Link Director 생성 ( 이넘은 뭔지 아직 모르겠음)
// 5a. If it fails, it will use an NSTimer director
// 5a. 실패시에는 NSTimer director를 사용
// 6. It will try to run at 60 FPS
// 6. 1초에 60번의 화면을 갱신하도록 기본 셋팅
// 7. Display FPS: NO
// 7. 화면 갱신 속도(FPS : Frame Per Second)를 표시하지 않음
// 8. Device orientation: Portrait
// 8. Portrait (세로방향)으로 화면을 표시
// 9. Connects the director to the EAGLView
// 9. 생성된 director를 OpenGL ES View에 연결
CC_DIRECTOR_INIT();
// Obtain the shared director in order to...
CCDirector *director = [CCDirector sharedDirector];
// Sets landscape mode
// 화면을 Portrait (세로방향)가 아니라 Landscape(가로방향)으로 변경
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
// Turn on display FPS
// 화면갱신 속도를 표시함으로 변경
[director setDisplayFPS:YES];
// Turn on multiple touches
EAGLView *view = [director openGLView];
// 멀티터치 구현
[view setMultipleTouchEnabled:YES];
// Default texture format for PNG/BMP/TIFF/JPEG/GIF images
// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
// You can change anytime.
// 화면사용해상도는 16bit에서 32Bit로 변경
[CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];
// 사용자 구현 Scen 호출
[[CCDirector sharedDirector] runWithScene: [HelloWorld scene]];
}
1) applicationDidFinishLaunching() : 어플리케이션이 생성준비가 완료된 후 호출되는 함수
ㄱ. 프로그래밍 가능한 최초함수 (?) : MFC의 CApp:: InitInstance() 와 비슷?
2) CC_DIRECTOR_INIT() : cocos2D 화면에 대한 초기화 세팅함수로 주요 기능은 다음과 같다.
// 1. OpenGL ES 화면을 depth buffer를 사용하지 않고, 화면은 16bit color(565) 방식으로 세팅
// 2. 멀티터치는 사용하지 않음
// 3. UIWindow를 생성하고 "window"변수에 연결
// 4. OpenGL ES구현 뷰인 UIWindow를 새로생성된 window에 연결생
// 5. Display Link Director 생성 ( 이넘은 뭔지 아직 모르겠음)
// 5a. 실패시에는 NSTimer director를 사용
// 6. 1초에 60번의 화면을 갱신하도록 기본 셋팅
// 7. 화면 갱신 속도(FPS : Frame Per Second)를 표시하지 않음
// 8. Portrait (세로방향)으로 화면을 표시
// 9. 생성된 director를 OpenGL ES View에 연결
3) CC_DIRECTOR_INIT() 함수와 다른 특성을 재 설정
4) 사용자 구현 Scene 클래스 호출 ( HelloWorld scen)
3. HelloWorld::init()
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init] )) {
// create and initialize a Label :
// CCLabel 생성 : 글자체, 글씨 크기 지정
CCLabel* label = [CCLabel labelWithString:@"Hello World" fontName:@"Marker Felt" fontSize:64];
// ask director the the window size :
CGSize size = [[CCDirector sharedDirector] winSize];
// position the label on the center of the screen
label.position = ccp( size.width /2 , size.height/2 );
// add the label as a child to this Layer
[self addChild: label];
}
return self;
}
4) HelloWorld::scene()
+(id) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
HelloWorld *layer = [HelloWorld node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
ㄴ. CCScene클래스에 CCLayer를 추가
'아이폰개발 > cocos2d' 카테고리의 다른 글
[cocos2d] Scene 추가 및 화면 전환효과 구현 (0) | 2010.07.24 |
---|---|
[cocos2D]초기 메뉴 구현하기 (0) | 2010.07.19 |
[cocos2D]주요 클래스 검토 : CCScene, CCDirector, CCLayer, CCScene, CCNode (0) | 2010.07.18 |
[cocos2d] 준비 및 설치하기 (1) | 2010.07.15 |