「Cocos2D」タグアーカイブ

cocos2d-iphone-2.1をインストール

cocos2d-iphoneをダウンロード
https://code.google.com/p/cocos2d-iphone/downloads/list

cocos2d-iphone-2.1.tar.gzが最新のようなので、ダウンロードします。

「ターミナル」を起動して、以下のコマンドを入力

①Downloadsにファイルが入っているのでDownloadsに移動
[php]
$ cd ~/Downloads
[/php]
②解凍します。
[php]
$ tar xzvf cocos2d-iphone-2.1.tar.gz
[/php]
③解凍後で出来たディレクリへ移動
[php]
$ cd cocos2d-iphone
[/php]
④cocos2d-iphoneディレクリの中のファイルinstall-templates.shを実行
[php]
$ ./install-templates.sh
[/php]

Xcodeを起動し、テンプレートが出来ていればインストール完了

ViewControllerの書き方

①「ViewController.h」に
[php]
//————————————————-//
//フレームワークをインポート
//————————————————-//
#import <UIKit/UIKit.h>

//————————————————-//
//クラスとインスタンス変数の宣言
//————————————————-//
@interface ViewController : UIViewController <UIAlertViewDelegate,UIActionSheetDelegate>

//————————————————-//
//アクセサメソッドの宣言を
//————————————————-//

//————————————————-//
//オリジナルメソッドの宣言
//————————————————-//
– (void)configureView;
– (void)alertOKCancel;
– (void)actionOKCancel;

//————————————————-//
//ヘッダーファイル
//————————————————-//
@end

[/php]

②ViewController.m
[php]
/————————————————-//
//ヘッダーファイルをインポート
//————————————————-//
#import "ViewController.h"

@interface ViewController ()
@end

//————————————————-//
//クラスとアクセサメソッドの実装
//————————————————-//
@implementation ViewController

//————————————————-//
// 処理
//————————————————-//
– (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

// ビューの設定をまとめて行うメソッドを呼び出します。
[self configureView];
}

//————————————————-//
// ビュー[.hのオリジナルメソッド]
//————————————————-//
– (void)configureView
{
UIButton *customButton1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
customButton1.frame = CGRectMake(40.0, 100.0, 240.0, 40.0);
[customButton1 setTitle:@"アラート" forState:UIControlStateNormal];
[customButton1 addTarget:self action:@selector(alertOKCancel) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:customButton1];

UIButton *customButton2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
customButton2.frame = CGRectMake(40.0, 180.0, 240.0, 40.0);
[customButton2 setTitle:@"アクションシート" forState:UIControlStateNormal];
[customButton2 addTarget:self action:@selector(actionOKCancel) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:customButton2];
}

//————————————————-//
// [.hのオリジナルメソッド]
//————————————————-//
– (void)alertOKCancel
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"アラート"
message:@"よろしいですか?"
delegate:self
cancelButtonTitle:@"いいえ"
otherButtonTitles:@"はい", nil];
[alert show];
}

– (void)actionOKCancel
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"アクションシート"
delegate:self
cancelButtonTitle:@"いいえ"
destructiveButtonTitle:@"はい"
otherButtonTitles:nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];
}

//————————————————-//
// デリゲートメソッド
//————————————————-//
– (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}

– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

– (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"『%d番』のボタンが押されました!",buttonIndex);
}

– (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"『%d番』のボタンが押されました!",buttonIndex);
}

//————————————————-//
// メソッドファイルend
//————————————————-//
@end

[/php]