cocos2d-x現時点バージョン3.17でも、コマンドで生成したデフォルトプロジェクトでは、iOS版が何も変更せずに、デバイスを上下反転すると、画面の向きも自動的に回転してくれると思いますが、Android版では未だに画面の自動回転に対応していないようです。
実はAndroid版の対応方法も簡単です。
プロジェクトルート/proj.android/app/src/org/cocos2dx/cpp/AppActivity.javaを開き、onCreate()のところに以下のソース3行を追加するだけです。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); }
これだけです!
そしたらファイル全体がこんな感じになると思います。
package org.cocos2dx.cpp; import android.os.Bundle; import org.cocos2dx.lib.Cocos2dxActivity; public class AppActivity extends Cocos2dxActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.setEnableVirtualButton(false); super.onCreate(savedInstanceState); // ここから if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } // ここまで // Workaround in https://stackoverflow.com/questions/16283079/re-launch-of-activity-on-home-button-but-only-the-first-time/16447508 if (!isTaskRoot()) { // Android launched another instance of the root activity into an existing task // so just quietly finish and go away, dropping the user back into the activity // at the top of the stack (ie: the last state of this task) // Don't need to finish it again since it's finished in super.onCreate . return; } // DO OTHER INITIALIZATION BELOW } }