
先月、参考書を写経してGame Center対応のゲームの作り方を知ったので、必要最低限なシュウォッチアプリを作ろうと思った。けど、思うだけで何もしてなかったのだけど、@ITでマルチタッチに関する記事を見て思い出した。記事によると、マルチタッチの検出にはUIResponderクラスのtouchesBegan, touchesMoved, touchesEnded, touchesCancelledメソッドを実装するみたい。シュウォッチアプリに関しては、ボタンのViewそれぞれのタップイベントを拾ったら大丈夫そうだけど、わからないので試してみた。UIResponderのメソッドを実装しなくても大丈夫そう。
ViewController.h
#import <UIKit/UIKit.h> @interface ViewController : UIViewController // Buttonのタップ回数 @property (assign) NSInteger numButton; @property (assign) NSInteger numButtonA; @property (assign) NSInteger numButtonB; // Buttonのタップ回数を表すラベル @property (weak) IBOutlet UILabel *numButtonLabel; @property (weak) IBOutlet UILabel *numButtonALabel; @property (weak) IBOutlet UILabel *numButtonBLabel; // Buttonをタップしたときの処理 - (IBAction)tapButtonA:(id)sender; - (IBAction)tapButtonB:(id)sender; @end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
// プロパティに対応するメンバー変数とアクセサメソッドの生成
@synthesize numButton = _numButton;
@synthesize numButtonA = _numButtonA;
@synthesize numButtonB = _numButtonB;
@synthesize numButtonLabel = _numButtonLabel;
@synthesize numButtonALabel = _numButtonALabel;
@synthesize numButtonBLabel = _numButtonBLabel;
// イニシャライザ
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
// メンバー変数の初期化
_numButton = 0;
_numButtonA = 0;
_numButtonB = 0;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Buttonの押下回数を表示する
NSString *strNum = [NSString stringWithFormat:@"%d", self.numButton];
self.numButtonLabel.text = strNum;
NSString *strNumA = [NSString stringWithFormat:@"%d", self.numButtonA];
self.numButtonALabel.text = strNumA;
NSString *strNumB = [NSString stringWithFormat:@"%d", self.numButtonB];
self.numButtonBLabel.text = strNumB;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
// ButtonA, Bをタップしたときの処理
- (IBAction)tapButtonA:(id)sender
{
self.numButton++;
self.numButtonA++;
self.numButtonLabel.text = [NSString stringWithFormat:@"%d", self.numButton];
self.numButtonALabel.text = [NSString stringWithFormat:@"%d", self.numButtonA];
}
- (IBAction)tapButtonB:(id)sender
{
self.numButton++;
self.numButtonB++;
self.numButtonLabel.text = [NSString stringWithFormat:@"%d", self.numButton];
self.numButtonBLabel.text = [NSString stringWithFormat:@"%d", self.numButtonB];
}
@end
これからの予定(シュウォッチアプリに必要なこと)
- アプリコア(起動・終了/画面遷移)
- ゲームコア(タイマーのOn/Off/ボタン連打のカウント)
- Game Centerの実装
- 広告の挿入
- [オプション]グラフィック
- [オプション]効果音・BGM
広告はiAdやAdMobとかがあると思うのだが、よくわかってないので、ゲームに組み込む前に独立してお試しプロジェクトを作ろう。
参考サイト
iPhoneソーシャルゲーム開発
posted with amazlet at 12.07.12
林 晃
シーアンドアール研究所
売り上げランキング: 245996
シーアンドアール研究所
売り上げランキング: 245996
関連エントリー
