cocos2d-xでportraitゲームを作る
cocos2d-xのデフォルトで作ったプロジェクトはlandscape設定されています。
が、気軽にできるゲームとしては片手でできるportraitモードにしたいという人も多いでしょう。
縦横の変更は簡単ですが、cocos2d-xからではなくiOS、Androidそれぞれのネイティブのコードでそれぞれ管理します。
iOS
変更する箇所は大きく2つあります。
1つは、TargetsのDeployment infoでDevice OrientationでPortraitを選択します。
2つ目は、以下のコードを変更します。
- RootViewController.mm
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return UIInterfaceOrientationIsPortrait(interfaceOrientation); // return UIInterfaceOrientationIsLandscape( interfaceOrientation ); } - (NSUInteger) supportedInterfaceOrientations{ #ifdef __IPHONE_6_0 return UIInterfaceOrientationMaskPortrait; // return UIInterfaceOrientationMaskAllButUpsideDown; #endif }
Android
Androidの変更箇所は一カ所だけです。
AndroidManifest.xmlファイルのandroid:screenOrientation="landscape"となっているラインを、android:screenOrientation="portrait"に変更します。
- AndroidManifest.xml
<activity android:name="org.cocos2dx.cpp.Cocos2dxActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:configChanges="orientation"> </activity>