More Related Content
Similar to cocos2d-xにおけるBox2Dの利用方法および便利なツール (20)
More from Tomoaki Shimizu (20)
cocos2d-xにおけるBox2Dの利用方法および便利なツール
- 2. 清水 友晶
— 株式会社TKS2
http://tks2.net
— スマートフォンアプリ開発
(iOS, Android, Windows Phone 8)
Webコンテンツ開発
— cocos2d-xへの開発参加
cocos2d-xを利用したアプリ開発
講演活動
執筆活動
— Twitter: tks2shimizu
— Blog: http://tks2.net/memo
— SlideShare: http://www.slideshare.net/doraemonsss
— Facebook: http://www.facebook.com/doraemonsss
- 6. — 4/17 第7回 shinjuku.cocos2d-x
— 4/20 cocos2d-xハンズオン勉強会
— 5/15 shinjuku.cocos2d-x初心者ハンズオン
∼MacでiOSアプリを作る開発環境を整えよう!∼
— 5/17 cocos2d-x公開講座 in 鹿児島
— 5/18 cocos2d-x実践講座 in 鹿児島
— 5/22 第8回 shinjuku.cocos2d-x
— 6/M shinjuku.cocos2d-x初心者ハンズオン
∼MacでAndroidアプリを作る開発環境を整えよう!∼
— 6/M 第9回 shinjuku.cocos2d-x
- 14. プロジェクトの準備
— project-creatorによるプロジェクト作成
./create_project.py -project pinball -package net.tks2.pinball -
language cpp
— ゲームで使用する画像を「Resources」に配置
http://tks2.net/pinball/pinball.zip
— Xcodeの場合は、プロジェクトへ取り込む
— GB2ShapeCache-xクラスを「Classes」に配置
https://github.com/tks2shimizu/GB2ShapeCache-x
— Xcodeの場合は、プロジェクトへ取り込む
— Android向けは、Android.mkにGB2ShapeCache-x.cppを追加
cocos2d-2.1rc0-x-2.1.2/projects/pinball/proj.android/jni/Android.mk
- 19. PhysicsEditor
— パラメータ設定
— アンカーポイント
— 密度
— 反発係数
— 摩擦係数
— センサー
— 任意の文字列
— ファイル出力 … Publicボタン
— 出力されたplistファイルを「Resources」ディレクトリへ配置
— Xcodeの場合は、プロジェクトへ取り込む
- 20. cocos2d-xの縦画面表示
— iOS
— Supported Interface Orientations
— RootViewController.mm
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)in
return UIInterfaceOrientationIsPortrait( interfaceOrientation );!
}!
!
// For ios6, use supportedInterfaceOrientations & shouldAutorotate instea
- (NSUInteger) supportedInterfaceOrientations{!
#ifdef __IPHONE_6_0!
return UIInterfaceOrientationMaskPortrait;!
#endif!
}!
- 21. cocos2d-xの縦画面表示
— Android
— AndroidManifest.xml
<activity android:name=".NyanBall"!
android:label="@string/app_name"!
android:screenOrientation="portrait"!
android:theme="@android:style/Theme.NoTitleBar.
android:configChanges="orientation">!
<intent-filter>!
<action android:name="android.intent.action.MAIN"
<category android:name="android.intent.category.L
</intent-filter>!
</activity>
- 22. 背景画像の表示
— 今回は1つの画像のみを利用して、マルチレゾリュー
ション対応を行う
— AppDelegate.cpp
bool AppDelegate::applicationDidFinishLaunching() {!
CCDirector* pDirector = CCDirector::sharedDirector();!
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();!
!
pDirector->setOpenGLView(pEGLView);!
pDirector->setDisplayStats(true);!
pDirector->setAnimationInterval(1.0 / 60);!
!
CCSize winSize = CCDirector::sharedDirector()->getWinSize();!
pDirector->setContentScaleFactor(1024 / winSize.height);!
!
CCScene *pScene = HelloWorld::scene();!
pDirector->runWithScene(pScene);!
!
return true;!
}!
- 25. 背景画像に物理構造を与える
— シェイプデータの読込み
— 「pinball.plist」を読込む
— b2BodyDefの定義
— type
— position … PTM Ratioで割ることに注意
— userData … CCSpriteを追加
— ソース編集
— HelloWorldScene.h
— HelloWorldScene.cpp
https://gist.github.com/tks2shimizu/e69d420bc53675d982c3
- 26. ボールの作成
— タップを有効
— 毎フレーム処理
— ボール作成処理
— ソース編集
— HelloWorldScene.h
— HelloWorldScene.cpp
https://gist.github.com/tks2shimizu/
57e6ca5ff1494a66421e
- 28. 点数の表示
— 衝突判定
— b2ContactListenerクラス
— ソース編集
— HelloWorldScene.h
— HelloWorldScene.cpp
https://gist.github.com/tks2shimizu/
beb45a3a5e6625eb679f