cocos2d ピンボールゲーム
cocos2dで作るiPhone&iPadゲームプログラミング13章
シェイプ:凸形と逆時計回り
衝突ポリゴンは
- 反時計回りで定義される頂点
- 凸型のポリゴン
サンプルプログラムからピンボールの移植
本とはcocos2dやbox2dのバージョンが違うので変更点がいくつか。
新規にcocos2dプロジェクト作成後の話。
移植するソース
他の章と同じくClasses、Resourcesコピー。Targetのチェックを忘れずに。
ResourcesはプロジェクトのResourcesにあるファイルは除外
Classesは以下のファイルをコピーしない。
GameConfig.h GLES-Render.h GLES-Render.mm PhysicsBox2dAppDelegate.h PhysicsBox2dAppDelegate.mm RootViewController.h RootViewController.mm
スリープの設定の仕方がコンストラクタからメソッドに変わっていた。
world = new b2World(gravity); world->SetAllowSleeping(true);
SetAsEdge()が無くなっていた。とりあえず引用。
http://hamken100.blogspot.jp/2012/03/cocos2dbox2d.html
b2PolygonShape
ワールドの外枠に static オブジェクトの壁を作る時に、b2PolygonShape の SetAsEdge()関数を使っている人も多いと思いますが、これは 2.2.1 では廃止されました。代わりに b2EdgeShape というクラスに置き換えます。
b2EdgeShape は2点を結ぶ直線を当たり判定とするものなので、この変更はより専門化したクラスに分化されたと見れます。
b2DebugDraw::e_shapeBit→b2Draw::e_shapeBit
縦向き
■ソースの改修
AppDelegate.m // Supported orientations: Landscape. Customize it for your own needs - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { //横表示部分をコメントアウトし、縦表示に変更。 // UIInterfaceOrientationIsLandscape → UIInterfaceOrientationIsPortrait //return UIInterfaceOrientationIsLandscape(interfaceOrientation); returnUIInterfaceOrientationIsPortrait(interfaceOrientation); }
シミュレーターも縦にする方法。
プロジェクトのサマリーでiPhone/iPodDeploymentInfoからSupportedInterfaceOrientationsを設定するか、Info.plistを編集する。
Info.plist Supported interface orientations (修正前) Item 0 Landscape (left home button) Item 1 Landscape (right home button) (修正後) Item 0 Portrait (bottom home button) Item 1 Portrait (top home button)
※Item 1の修正はいらないかも
ccConfig.hのCC_ENABLE_GL_STATE_CACHEを有効に
参考:

cocos2dで作る iPhone&iPadゲームプログラミング
- 作者: Steffen Itterheim,畑圭輔,坂本一樹,加藤寛人,高丘知央,株式会社クイープ
- 出版社/メーカー: インプレスジャパン
- 発売日: 2011/06/24
- メディア: 単行本(ソフトカバー)
- 購入: 9人 クリック: 597回
- この商品を含むブログ (25件) を見る