(感谢cocos2d-x 的小明同学)
1:效果
2:实现
原理:将屏幕设置为竖屏,然后CCDirector::setDeviceOrientation()设置为cocos2d-x为横屏。
在这种转屏模式下,控件是不会旋转的
缺点:所有Android原生控件仍然是竖立的
注意事项:
ccTouchesBegan,ccTouchesMoved, ccTouchesEnded传入的坐标值仍然是屏幕坐标。即如果有必要,需要x和y值互调一下。
2.1 修改AndroidManifest.xml
将android:screenOrientation 属性设置为:portrait
<activity android:name=".pyramdAn"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation">
2.2 修改AppDelegate.cpp
bool AppDelegate::initInstance()
{
.......
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// OpenGLView initialized in HelloWorld/android/jni/helloworld/main.cpp
// the default setting is to create a fullscreen view
// if you want to use auto-scale, please enable view->create(320,480) in main.cpp
// if the resources under '/sdcard" or other writeable path, set it.
// warning: the audio source should in assets/
// cocos2d::CCFileUtils::setResourcePath("/sdcard");
CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
#endif // CC_PLATFORM_ANDROID
then, go....
只测试了Android,IOS没测试过。