Hello World

iOS/Cocos2d Tutorials 2010. 9. 17. 18:34

cocos2d 설치에 성공했다면 Xcode를 다시 실행시켜보자.

현재의 버전에서는(stable:0.99.4, beta:0.99.5) 다음과 같은 화면이 뜰 것이다.



세 가지 템플릿의 용도야 다르겠지? (아직 공부 안해서 모름 -_-;)
일단 cocos2d Application 한번 열어봅세!
프로젝트 명은 HelloWorld 로 뻔하게 했다.



뭐가 뭔진 모르겠지만 실행해보니 Hello World가 잘 뜬다!



그럼 소스를 슬슬 봐볼까..?

음.. 음..

"HelloWorldAppDelegate.m"


CCDirector 초기화 해주는 매크로가 보이고..
director를 사용하게 해주려고 공유하는 느낌의 생성도 보이고..
방향 설정이 보이고..
FPS 표시 한다는것도 보이고..
멀티 터치를 사용한다는 것도 보이고..
텍스쳐 포맷 설정도 보인다.

마지막에 보니 HelloWorld 인스턴스를 생성도 안하고 scene 호출을 하네!?
scene이 클래스 메소드인가보다..
그럼 HelloWorld 클래스에 scene이 구현이 되있나..?

오케이.. 상속받은 메서드를 그냥 썼던거였으면 귀찮게 찾을뻔 했지만.. 있다!

"HelloWorldScene.m"

CCScene 클래스로 scene 인스턴스 생성을 위해 CCScene 클래스의 node 호출하고..
HelloWorld 클래스로 layer 인스턴스 생성을 위해 HelloWorld 클래스의 node 호출하고..
마지막엔 scene에다가 layer를 갖다 붙이는군..

node는 뭐지?
뒤적거려보니 CCNode.m에 정의되있다는군.

오.. 찾았다..

"cocos2d Sources/cocos2d/CCNode.m"


뭐야 -_-; 그냥 초기화해서 autorelease pool에 등록만 시키네 -_-
일반적인 클래스 생성할 때 new에 autorelease만 추가한거구만?
흠.. 그럼 앞으로 CCScene 객체 생성할 때는 new 대신 node 쓰면 되겠군..
release도 안해도 되고 굿.

그럼 이제 HelloWorld 클래스 초기화는 어떻게 하나 볼까?
delegate에서는 Hello World라는 글자 입력도 없었으니까..

"HelloWorldScene.m"


Interface Builder를 사용안하니 수제로 만드네 -_-ㅋ
labelWithString: fontName: fontSize: 메서드로 문자열, 글자체, 크기까지 한방이군. 굿

postion은 위치 정하는 거겠고.. winSize랑 ccp 매크로 보니 size는 윈도우 사이즈 받아오는거군 -_-ㅋ

CCDirector는 책에서 보니 싱글톤 객체랜다. 한 앱에 하나밖에 없는.
더 유식하게 말하면 하나의 SandBox에 유일한 객체, NSNotification같은 놈인듯.
이름따라 Scene을 관리한다고 적혀있는걸 본것 같다!

마지막엔 Hello World 문자열이 글자체, 크기가 설정된 채로 가운데 위치한 Label을 자기 자신.. HelloWorld라는 이름의 Scene에 붙였다.

이걸로 HelloWorld 살펴보기는 끝 -_-
다음은 바로 메뉴 만들기 고곡

'iOS > Cocos2d Tutorials' 카테고리의 다른 글

cocos2d SimpleAudioEngine  (0) 2010.11.03
메뉴 화면 만들기~!  (0) 2010.10.24
cocos2d 0.99.4 -> 0.99.5 beta3 로 버전 변경  (0) 2010.10.22
cocos2d setup guide  (0) 2010.09.01
Tutorials 포스팅 예정..  (0) 2010.08.31
Posted by 독뽀
,


설치 페이지가 한글도 있는데 옛날꺼라서 귀찮지만 상세히 작성함..

당연히 맥 상에 iOS SDK & Xcode가 설치되어있다는 전제 하에 써내려갑니다.
먼저 cocos2d 홈페이지로 가봅시다.

URL : http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:index

위키답게 깔끔하니 곧바로 빨간 네모로 표시된 곳을 클릭


자.. 다음엔 필요한 파일들을 다운받아야겠죠.. 역시 빨간 네모의 링크 클릭


새 창이 로딩되었으면 홈페이지에 나와있듯이 Stable Version을 다운받습니다. (베타 써도 무방하나 안정된거 씁시다 좀..)



다운로드받았으면 이제 다운받은 파일을 더블클릭해서 압축을 해제합니다.
이제 터미널을 실행시켜서 해당 폴더로 이동합니다. 그리고 다음 명령어를 입력 후 엔터!
비밀번호 물으면 비밀번호 입력하시고, 설정한 적이 없으면 그냥 엔터!
(만약 한 번 설치한 적이 있어서 폴더가 있는 경우엔 끝에 -f 옵션을 붙여주고, 사용자 디렉토리에 풀고 싶으면 끝에 -u 옵션을 주면 됩니다..)

sudo ./install-templates.sh


설치가 끝나면 cocos2d 템플릿은 /Library/Application Support/Developer/Shared/Xcode 경로에.
샘플들은 다운받은 폴더에 설치됩니다.

그럼 이제 실행시켜봐야겠죠? 샘플이 있는 우리가 다운받은 폴더로 가서 cocos2d-iphone.xcodeproj 파일을 실행!
현재 상태에서 일단 전체 컴파일을 한 번 하고 필요한 샘플들을 실행시켜보기로 합시다. (Cmd+B)

시간이 꽤 걸리니 티 타임 ㄱㄱ..
에러나 워닝은 일단 무시하고(궁금하면 구글링 ㄱㄱ -_-;)
상단 메인 메뉴의 Project → Set Active Target 에서 원하는 예제를 선택하고 위 버튼 클릭! (혹은 Cmd+R)
실행 화면이 뜨나요!? 떴다면 이제부터 구글링과 함께 공부합시다~!

'iOS > Cocos2d Tutorials' 카테고리의 다른 글

cocos2d SimpleAudioEngine  (0) 2010.11.03
메뉴 화면 만들기~!  (0) 2010.10.24
cocos2d 0.99.4 -> 0.99.5 beta3 로 버전 변경  (0) 2010.10.22
Hello World  (0) 2010.09.17
Tutorials 포스팅 예정..  (0) 2010.08.31
Posted by 독뽀
,

Agenda


모바일 프로그래밍/게임 프로그래밍 두 과목 모두 iOS(cocos2d)용인데..
내용 봐서 너무 비슷하다 싶으면 하나는 Android로 바꾸던지 해서 올릴 예정 (9월 2일/3일 첫 수업)
예상컨데 첫 주라 O.T.만 하고 말듯, 3일에 교수님께 여쭤보고 결정!
수강 정정기간이 4일 자정까지니 5일까지는 결론이 날듯..


아마도 학교 수업 내용보다는 광범위 혹은 빠르게 다룰듯..

9월 2/3일 : 비슷한 내용인지 확인 후 수강 확정
9월 7/8일 : 포스팅 시작


포스팅 내용 : cocoa framework/cocos2d 또는 cocos2d/NDK


Comming soon!

포스팅 내용이 cocos2d 위주로 갈 듯..
cocoa framework 이하 UIKit 관련 자료들은 skill에서만 당분간 다룰 예정

'iOS > Cocos2d Tutorials' 카테고리의 다른 글

cocos2d SimpleAudioEngine  (0) 2010.11.03
메뉴 화면 만들기~!  (0) 2010.10.24
cocos2d 0.99.4 -> 0.99.5 beta3 로 버전 변경  (0) 2010.10.22
Hello World  (0) 2010.09.17
cocos2d setup guide  (0) 2010.09.01
Posted by 독뽀
,
원본: http://iphonedevelopertips.com/user-interface/uialertview-without-buttons-please-wait-dialog.html
출처: http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=7462&MAEULNO=911&no=52368&page=1

If you’ve ever wanted to show a simple “please wait” dialog without resorting to a custom view, UIAlertView is a good option, and is even more appropriate if you customize the alert such that no buttons are shown.

In the figure below you can see how a simple alert can be shown (sans buttons) while you are busy doing some other system activity (reading/writing files, etc).


UIAlertView without Buttons
UIAlertView *alert;
 
...
 
alert = [[[UIAlertView alloc] initWithTitle:@"Configuring Preferences\nPlease Wait..." 
  message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
 
[alert show];

Trouble with this approach is that things look a little lopsided, as there is a significant amount of dead space on the bottom where the button(s) are to be shown. We can fix this by adding a few newline characters at the start of our message:

UIAlertView *alert;
 
...
 
// Add two newlines characters at the start of the message
alert = [[[UIAlertView alloc] initWithTitle:@"\n\nConfiguring Preferences\nPlease Wait..." 
  message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
 
[alert show];

The text is nearly centered, yet we’ve created a different problem, there is now white space on the top and bottom. There is one more approach…

UIAlertView with UIActivity Indicator

In the whitespace on the bottom, let’s add an activity indicator. Also, remove the newlines in the message text so the text starts near the top:

UIAlertView *alert;
 
...
 
alert = [[[UIAlertView alloc] initWithTitle:@"\n\nConfiguring Preferences\nPlease Wait..." 
  message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];

[alert show];
 
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] 
  initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];

Dismissing the Buttonless UIAlertView

Since there are no buttons associated with the alert, we have to dismiss the alert ourselves, versus the traditional approach where the system dismisses the alert when a button is pressed.

Here is the call to dismiss the alert:

[alert dismissWithClickedButtonIndex:0 animated:YES];

'iOS > Skills' 카테고리의 다른 글

모달 뷰 사용(일종의 팝업 윈도우)  (1) 2010.11.23
애니메이션 주기  (0) 2010.11.10
MBProgressHUD  (0) 2010.07.21
UIBarButtonSystemItem 추가된 아이템  (0) 2010.07.21
UIAlertView 커스터마이징  (0) 2010.07.21
Posted by 독뽀
,

MBProgressHUD

iOS/Skills 2010. 7. 21. 19:54

원본: http://github.com/jdg/MBProgressHUD
출처: http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=7462&MAEULNO=911&no=52297&page=1


MBProgressHUD

MBProgressHUD is an iPhone drop-in class that displays a translucent HUD with a progress indicator and some optional labels while work is being done in a background thread. The HUD is meant as a replacement for the undocumented, private UIKit UIProgressHUD with some additional features.

 

Adding MBProgressHUD to your project

The simplest way to add the MBProgressHUD to your project is to directly add the MBProgressHUD.h and MBProgressHUD.m source files to your project.

  1. Download the latest code version from the repository (you can simply use the Download Source button and get the zip or tar archive of the master branch).
  2. Extract the archive.
  3. Open your project in Xcode, than drag and drop MBProgressHUD.h and MBProgressHUD.m to your classes group (in the Groups & Files view).
  4. Make sure to select Copy items when asked.

Usage

A full Xcode demo project is included in the Demo directory. This should give you an idea how to use the class.

Posted by 독뽀
,
출처: http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=7462&MAEULNO=911&no=52201&page=1

UIBarButtonSystemItem은 아래 링크와 같이 정의되어 있음(사파리에서 제대로 보임)

http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIBarButtonItem_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40007519-CH3-SW2

 

 

위 그림과 같이 100부터 문서화 되지 않은 아이템이 있음

 

 Value

Image name 

100

UIButtonBarLocate.png

101

UIButtonBarArrowLeft.png

102

UIButtonBarArrowRight.png

103

UIButtonBarArrowUp.png

104

UIButtonBarArrowDown.png

105

UIButtonBarArrowLeft.png

106

UIButtonBarArrowRight.png

107

UIButtonBarPreviousSlide.png

108

UIButtonBarNextSlide.png

109

UIButtonBarPageCurl***.png

 

 

UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:(UIBarButtonSystemItem)107 target:self action:NULL];

 

이런식으로 쓰면 됨.

'iOS > Skills' 카테고리의 다른 글

UIAlertView without Buttons - Please Wait Dialog  (0) 2010.07.21
MBProgressHUD  (0) 2010.07.21
UIAlertView 커스터마이징  (0) 2010.07.21
UIImage 마스크(스텐실) 효과 주기 - Core Graphics  (0) 2010.07.21
UINavigationBar 커스터마이징  (0) 2010.07.21
Posted by 독뽀
,

원본: http://joris.kluivers.nl/iphone-dev/?p=CustomAlert
출처: http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=7462&MAEULNO=911&no=51914&page=1

iPhone SDK는 사용자에게 팝업을 보여주기 위한 UIAlertView 클래스를 제공합니다. 예를 들어, 애플은 이 팝업을 문자 메시지가 도착했을 때 사용합니다. 어플리케이션 개발자들은 이와 같은 팝업을 사용할 수 있습니다. 최상위의 특수한 윈도우 레벨에 보여집니다. 팝업 아래의 컨텐츠들에 대한 사용자의 입력은 팝업이 사라질 때까지 무시됩니다.


나의 최근 프로젝트들 중, 하나의 뷰가 모든 다른 컨텐츠들의 최상위에 보여져야만 했습니다. Spotlight dim effect와 사용자 입력을 막는 것은 재사용할 수 있었으나, 파란색의 UIAlertView 스타일은 나의 요구와 맞지 않았습니다. 처음부터 나만의 뷰를 만드는 대신, UIAlertView가 제공하는 것을 재사용하고 모든 불필요한 기능들을 제거하기로 결심했습니다.

이 페이지는 아래에 나온 피가 튀기는 것 같은 변형된 Alert를 생성하기 위해 무엇이 필요한지 설명할 것입니다.
 
A normal alert vs. a custom alert
 
팝업을 우리가 원하는 어떤 것으로든 변형할 수 있지만, 단순함을 유지하려고 했습니다. 피가 튀기는 팝업은 두 가지 주요 파트들로 구성되어져 있습니다. 배경 이미지와 텍스트 레이블. 위의 비교에서 볼 수 있듯이, 우리는 버튼과 기본 텍스트를 무시할 겁니다. 새로운 초기화 함수는 JKCustomAlert에게 정보를 제공하기 위해 사용될 것입니다.
 
- (id) initWithImage:(UIImage *)backgroundImage text:(NSString *)text;
 
자체 Initializer를 사용함으로써, 기본 타이틀과 메시지는 설정되지 않습니다. 만약 지금 시점에서 팝업을 보여준다면, 비어있고 작지만, 기본 모습을 가진 팝업이 나타날겁니다.

팝업의 배경을 기본에서 자체 배경으로 변경하기 위해서 drawRect: 는 Override 되어야 합니다. 우리가 해야할 것은 배경 이미지를 뿌리는 것 뿐입니다.

- (void) drawRect:(CGRect)rect {
    // do not call the super drawRect

    CGSize imageSize = self.backgroundImage.size;
    [self.backgroundImage drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
}
 
마지막으로 할 것은 배경 이미지의 크기에 맞게 JKCustomAlert의 크기를 변경하는 것입니다. show 함수는 팝업의 크기를 재설정하고 애니메이션할 책임이 있습니다. 에니메이션을 시작하고 뷰의 크기를 맞추기 위해 super 함수를 호출합니다.
 
- (void) show {
    // call the super show method to initiate the animation
    [super show];

    // resize the alert view to fit the image
    CGSize imageSize = self.backgroundImage.size;
    self.bounds = CGRectMake(0, 0, imageSize.width, imageSize.height);
}
 
팝업에 나타나는 Text label은 addSubView: 함수에 추가되고, 위치는 layoutSubviews 함수 안에서 설정됩니다.

사용자에게 버튼을 제공하지 않기 때문에, dismissWithClickedButtonIndex:animated셀렉터를 사용하여 팝업을 수동으로 없애야 합니다. 그렇지 않으면, 프로그램은 팝업이 보이는 동안 멈추어 있을 것입니다.
 

Sample Project

Download CustomAlert.zip (23kb)

'iOS > Skills' 카테고리의 다른 글

MBProgressHUD  (0) 2010.07.21
UIBarButtonSystemItem 추가된 아이템  (0) 2010.07.21
UIImage 마스크(스텐실) 효과 주기 - Core Graphics  (0) 2010.07.21
UINavigationBar 커스터마이징  (0) 2010.07.21
App Icon에 뱃지(Badge) 달기  (0) 2010.07.21
Posted by 독뽀
,
원본: http://iphonedevelopertips.com/general/remove-shine-gloss-effect-on-iphone-icon.html
출처: http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=7462&MAEULNO=911&no=51777&page=1

How to Mask an Image

'iOS > Skills' 카테고리의 다른 글

UIBarButtonSystemItem 추가된 아이템  (0) 2010.07.21
UIAlertView 커스터마이징  (0) 2010.07.21
UINavigationBar 커스터마이징  (0) 2010.07.21
App Icon에 뱃지(Badge) 달기  (0) 2010.07.21
앱 아이콘 반사효과 없애기  (0) 2010.07.21
Posted by 독뽀
,

출처: http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=7462&MAEULNO=911&no=51676&page=1

아래와 같이 배경색을 바꿀 수 있습니다.

You can change background color of navigation bar like this.

[[controller navigationBar] setTintColor:[UIColor colorWithRed:0.36 green:0.09 blue:0.39 alpha:1.00]];

 

타이틀은 다음과 같이 지정할 수 있습니다.

You can set the title like this. 

CGRect frame = CGRectMake(0, 0, 400, 44);
UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:20.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor blackColor];
label.text = navBar.topItem.title;
navBar.topItem.titleView = label;
Posted by 독뽀
,

출처: http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=7462&MAEULNO=911&no=51672&page=1

최근 수신한 메일이 있으면 iPhone, iPod touch 메일 아이콘에 빨간색 동그라미 안에 있는 숫자를 보실 수 있습니다.

최근 수신한 이메일 개수를 보여주기 위한 배지(Badge)인데, 최근 수신한 데이터나 최근 등록한 데이터가 있을 때 보여주게 하면 시각효과가 좋습니다.

방법은 아주 간단합니다.

You can see number inside circle in red when you've got email recently on iPhone, iPod touch mail application.
It calls "Badge" that shows quantity of your recent received email. If there are some new received data or registered data,
visual effect(for recognition) will be good.

How-to use the "Badge" is easy.

 

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:99];

 

 

 

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:123456];

 

 

Badge Number를 0으로 하면 뱃지가 사라집니다.

Setting "setApplicationIconBadgeNumber" to 0 (zero) will make disappeared the "Badge".

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

 

App을 종료하기 전에 위 코드를 실행해주면 종료후 iPhone 화면에 배지가 달린 아이콘을 보실 수 있습니다.

If you run above code before closing the application, you may see an icon with badge.

(추가)

위 내용은 델리게이트의 applicationWillTerminate: 메소드에 적용 시 iOS 4.0 이전에서는 이상이 없습니다.
4.0 이후라면 어플이 백그라운드로 진입 시 어떻게 할지 정한 후 (info.plist 파일에서 +누른 후 선택)
체크 한 경우에는 상관이 없고, (멀티 태스킹 미지원으로 설정)
체크 해제한 경우에는 어플이 백그라운드로 갈 때의 메소드에도 넣어주시면 됩니다. (멀티 태스킹 지원, 두 메소드 모두에 넣기)

(Addition)

Above article is for lower version than iOS 4.0 (support multi-tasking function).
Using higher iOS version(support multi-tasking function, after iOS 4.0), you must consider a matter in all its aspects whether you will use badge on multi-tasking environment.
You can set up on info.plist file. Add new option to info.plist on xcode by clicking + button.
Select Application does Not run in Background option.
Checking that option will not support multi-tasking, unchecking will support.
Checking that option is equal to this article, unchecking may make some code to application will run in background methods.

Posted by 독뽀
,