cocos2d-x Android项目主要活动背景上的不需要的TitleBar

时间:2016-07-15 17:11:17

标签: android cocos2d-x

我正在使用cocos2d-x框架开发移动游戏。在应用程序启动期间,由于第一个场景创建,黑屏上的冻结时间为500-600毫秒。我希望在此期间显示一个基本的闪屏。

我首先尝试跟随this example given by Chris Stewart,但没有成功,因为冻结时间恰好在主要活动构建之后发生。因此,启动时正确显示启动画面,但仍然会出现冻结黑屏。

为了达到我想要的效果,我现在尝试将表面视图放在窗口顶部,并为主要活动定义背景(即启动画面)。我发现实现这一目标的唯一方法是使用setZOrderOnTop方法。

主要活动会覆盖Cocos2dxActivity::onCreateView(),以便将表面视图放在窗口顶部:

public class AppActivity extends Cocos2dxActivity {

    @Override
    public Cocos2dxGLSurfaceView onCreateView() {
        Cocos2dxGLSurfaceView glSurfaceView = super.onCreateView();
        glSurfaceView.setZOrderOnTop(true);

        return glSurfaceView;
    }

}

AndroidManifest.xml基本上与cocos2d-x提供的默认主题相同,我只将主题更改为@style/SplashTheme,定义如下:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="xxx"
    android:installLocation="auto">

    <uses-feature android:glEsVersion="0x00020000" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher">

        <!-- Tell Cocos2dxActivity the name of our .so -->
        <meta-data android:name="android.app.lib_name"
                   android:value="xxx" />

        <activity
            android:name="xxx.AppActivity"
            android:screenOrientation="portrait"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@style/SplashTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

这是我的values/styles.xml,它只包含上面提到的基于Theme.NoTitleBar.Fullscreen的基本风格:

<resources>

    <style name="SplashTheme" parent="@android:style/Theme.NoTitleBar.Fullscreen">
        <item name="android:windowBackground">@drawable/splash</item>
    </style>

</resources>

drawable/splash.xml设置灰色背景并在屏幕中央显示一个图标:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@color/gray"/>

    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/ic_launcher"/>
    </item>

</layer-list>

这种配置似乎实现了我想要的。上面定义的背景就像一个闪屏,然后在500-600ms之后被第一个场景隐藏起来。 在加载过程中,顶部会出现一个不需要的白条(参见下图),并在加载完第一个场景后消失。

Screenshot 1 Screenshot 2

经过将近一天的努力寻找原因,我正在寻求帮助。

  • 这个白条的起源是什么?
  • 有没有更好的方法来实现我的目标?

0 个答案:

没有答案