'Hello World'에 해당되는 글 2건

  1. 2010.07.18 [cocos2d] Hello World 분석 1
  2. 2010.07.15 [cocos2d] 준비 및 설치하기 1
cocos2D를 설치하고 cocos2D Template만을 적용해서 생성되는 Hello World 구현과정을 살펴보자. 

기본으로 생성되는 프로젝트는 다음과 같이 구성된다.


주요 프로세스 확인하기

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;
}
    ㄱ. applicationDidFinishLaunching() 함수에서 직접호출   
    ㄴ. CCScene클래스에 CCLayer를 추가

Posted by 꿈을펼쳐라
,

아이폰 스터디를 찾아 해매던 차에, 구원의 손길을 주신 곳이 플래시카페(http://flashcafe.org)라는 곳이었는데, 이곳 스터디 명칭이 "아이폰/아이팟 게임제작 스터디"였다. 
사실, 게임에 약간은 과심이 있었지만, 게임제작은 나중에 여유있을 때 한번 해볼까? 하는 생각이었는데, 이곳 스터디에 참여하는 순간 선택의 여지가 없어졌다.  아이폰에서 가장 수익성 있는 분야 중하나이고, 이곳에서 게임 개발의 기초 및 게임 개발 분야에 있는 분들을 알아두면 좋겠다 싶어 열심히 공부하기로 했다.

1.  cocos2d 란 무엇인가? 
게임에서 가장 중요한 기술중 하나는 화면에 무엇을 뿌려주느냐이다.  데스트탑에서는 주로 MS의 Direct3D기술과 OpenGL기술을 사용하였지만, 모바일 단말기로 넘어오면서 OpenGL ES가 업계의 표준이 되었다. (http:/www.khronos.org)

 cocos2D는 이러한 openGL ES를 2D 게임개발에 보다 효율적으로 적용할 수 있도록 만들어 놓은 라이브러리/템플릿의 모임이다. 

2. OpenGL ES를 사용하면 되지 굳이 cocos2D를 사용할 필요가 있는가? 
물론, cocos2D는 OpenGL ES를 모아놓은 것이므로 OpenGL ES로 직접 구현가능하다.  하지만, 2D게임 개발에 필요한 많은 기능들을 쉽고 빠르게 적용할 수 있도록 만든 것이 cocos2D임으로 좀더 편하고, 빠르게 게임 개발이 가능하다.  그래도, 궁극적으로는 OpenGL ES에 대한 이해가 필요하므로 양쪽의 지식을 모두 확보하는 것이 좋으리라 생각된다. 


3. cocos2D 다운받기 
  1) 홈페이지 : http://www.cocos2d-iphone.org ->  download   tab
  2) 최신버전 ( iOS4용) : cocos2d-iphone-0.99.4-rc3.tar.gz

  3) 안정화버전 :   cocos2d-iphone -0.99.3.tar.gz


   (주의) 개발Tool을 최신버전(Xcode 3.2.3 : iOS4)를 사용한다면 2번을 그 이하버전을 사용한다면 3)번을 받으시면 된다. 


4. 설치하기 
  1) 다운받은 파일을 특정위치로 옯긴 후 압축을 풀어 놓음
  2) 터미널(응용프로그램->유틸리티->터미널)을 실생하고, 압축을 푼 위치로 이동 : Finder 에서 경로를 copy하여 사용  (cd, pwd, ls -l  명령어 이용) 
  3) ./install-templates.sh -u 을 이용하여 설치

Daniel-Leeui-MacBook-Pro:cocos2d-iphone-0.99.4-rc3 simverse$ ./install-templates.sh -u
cocos2d-iphone template installer
...creating cocos2d template directory




Installing cocos2d template
----------------------------------------------------

...creating destination directory: /Users/simverse/Library/Application Support/Developer/Shared/Xcode/Project Templates/cocos2d 0.99.4/cocos2d Application/
...copying template files
...copying cocos2d files
...copying cocos2d dependency files
...copying CocosDenshion files
...copying cocoslive files
...copying cocoslive dependency files
done!



Installing cocos2d + box2d template
----------------------------------------------------

...creating destination directory: /Users/simverse/Library/Application Support/Developer/Shared/Xcode/Project Templates/cocos2d 0.99.4/cocos2d Box2d Application/
...copying template files
...copying cocos2d files
...copying cocos2d dependency files
...copying CocosDenshion files
...copying cocoslive files
...copying cocoslive dependency files
...copying Box2D files
done!



Installing cocos2d + chipmunk template
----------------------------------------------------

...creating destination directory: /Users/simverse/Library/Application Support/Developer/Shared/Xcode/Project Templates/cocos2d 0.99.4/cocos2d Chipmunk Application/
...copying template files
...copying cocos2d files
...copying cocos2d dependency files
...copying CocosDenshion files
...copying cocoslive files
...copying cocoslive dependency files
...copying Chipmunk files
done!
...creating destination directory: /Users/simverse/Library/Application Support/Developer/Shared/Xcode/File Templates/cocos2d 0.99.4/



Installing CCNode file templates...
----------------------------------------------------

done!
Daniel-Leeui-MacBook-Pro:cocos2d-iphone-0.99.4-rc3 simverse$ 
[설치화면]


  4) 제대로 설치가 되었다면 Xcode -> create new Xcode Project 에서 다음과 같이  cocos2D template이 보일 것이다.

  ( 나의 경우, cocos2d 0.99.3과 cocos2d 0.99.4를 모두 설치하여 두개가 보인다.)

   4) 여기까지 온 김에 실제화면을 한번 확인해보자. 위의 화면에서 "cocos2d Application"을 선택하고 "Choose.." 버튼을 누르고, 프로그램을 실행시켜보자. 

   모든 프로그래밍의 시작 "Hello World"가 아래와 같이 나타난다. 



시작이 반이라고 하니, 이미 우리는 cocos2d 반은 배운 것이다. ^^  정말!!!
Posted by 꿈을펼쳐라
,