Android设备上的Cocos2dx横向和纵向

时间:2016-01-21 09:50:39

标签: android cocos2d-x

您好我正在学习cocos2dx。我正在纵向视图上构建这个游戏。问题是图像太小了。为什么呢?

landscape

portrait

另外如何让它隐藏导航栏?

1 个答案:

答案 0 :(得分:2)

对于AndroidManifest.xml中的纵向,将屏幕方向更改为纵向:

 <activity android:name="org.cocos2dx.cpp.AppActivity"
                  android:label="@string/app_name"
                  android:screenOrientation="portrait"
                  android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                  android:configChanges="orientation">

还在AppDelegate.cpp中设置了适当的设计分辨率(例如,当它为960x640时,对于potrait应为640x960)。

至于隐藏导航栏,您必须将目标sdk级别更改为api级别19(kitkat),然后更改以下内容的AppActivity类实现:

public class AppActivity extends Cocos2dxActivity {
    private Cocos2dxGLSurfaceView glSurfaceView;

    public Cocos2dxGLSurfaceView onCreateView()
    {
        glSurfaceView = new Cocos2dxGLSurfaceView(this);
        this.hideSystemUI();
        glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8);

        return glSurfaceView;
    }

    public void onWindowFocusChanged(boolean hasFocus)
    {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus)
        {
            this.hideSystemUI();
        }
    }

@TargetApi(Build.VERSION_CODES.KITKAT)
    private void hideSystemUI()
    {
        if (Build.VERSION.SDK_INT >= 19) {
            glSurfaceView.setSystemUiVisibility(
                    Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_LAYOUT_STABLE 
                    | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_FULLSCREEN
                    | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }
}

这只适用于Android 4.4及更高版本的设备,而老版本则不会做任何事情。