cocos2d

1. cocos2d 公開ページ
cocos2d

2. インストール方法
$ cd (cocos2dフォルダ)
$sudo ./install-templates.sh

xcodeでプロジェクトの新規作成時に cocos2d が選択できるようにプロジェクト テンプレートの登録が行われる

3. cocos2dで作る iPhone&iPadゲームプログラミング
インプレス社のサポートページ
著者のサポートページ

ミリ秒の計測を行う

1
2
3
4
5
6
7
8
9
// 時間計測を開始する
NSDate *startTime = [NSDate date];
 
// 時間計測する処理を行う
 
// 経過時間を計測する
NSTimeInterval elapsedTime = [startTime timeIntervalSinceNow];
NSString *elapsedTimeString = [NSString stringWithFormat:@"Elapsed time: %f 秒", -elapsedTime];
LOG(@"%@", elapsedTimeString);

Viewイメージをキャプチャーし、PNG画像で保存する

画面に表示されていないビューのキャプチャーを行う。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// UIImage を PNG画像データへ変換する
+ (BOOL)saveUIImage2PNG:(UIImage *)image FileName:(NSString *)fileName
{
    NSData *data = UIImagePNGRepresentation(image);  
    NSString *pngFilePath = [NSString stringWithFormat:@"%@/%@.png", [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"], fileName];  
    NSLog(@"%@", pngFilePath);
 
    BOOL result;
    if ([data writeToFile:pngFilePath atomically:YES]) {
        result = YES;
    } 
    else {
        result = NO;
    }
 
    return result;
}
 
// Viewイメージをキャプチャーする
// 備考: 画面に表示していなくてもキャプチャーできる
+ (UIImage *)captureViewImage:(UIView *)view 
{   
    UIImage *capture; 
 
    UIGraphicsBeginImageContext(view.bounds.size);
 
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    capture = UIGraphicsGetImageFromCurrentImageContext();
 
    UIGraphicsEndImageContext();
 
    return capture;
}