【发布时间】:2022-01-02 00:13:19
【问题描述】:
我为我的 Android 游戏创建了启动画面主题。但问题是我的启动画面在 OnCreate(Bundle bundle) 完全执行后自动结束,这导致在执行 Draw(GameTime gameTime) 之前出现黑屏。我在 Draw(GameTime gameTime) 中绘制我的游戏精灵。因此,在执行 Draw(GameTime gameTime) 之前一直黑屏。
当我的游戏代码已经达到 Draw(GameTime gameTime) 时,是否可以手动结束启动画面?我不希望在 OnCreate(Bundle bundle) 完全执行时启动画面已经结束。
splash_screen_svg.xml:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="320dp"
android:height="480dp"
android:viewportWidth="84.666664"
android:viewportHeight="127">
<path
android:pathData="M0.529,0.529h83.608v125.942h-83.608z"
android:strokeWidth="1.05833"
android:fillColor="#00ffff"
android:strokeColor="#000000"/>
<path
android:pathData="M21.431,32.015h41.804v62.971h-41.804z"
android:strokeWidth="0.529167"
android:fillColor="#ff0000"
android:strokeColor="#000000"/>
</vector>
colors.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<color name="splash_background">#eff1f7</color>
</resources>
字符串.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">splashapp</string>
</resources>
styles.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<style name="MainTheme" parent="MainTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MainTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
<item name="android:windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
<!-- colorPrimary is used for the default action bar background -->
<item name="android:colorPrimary">#2196F3</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="android:colorPrimaryDark">#1976D2</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="android:colorAccent">#FF4081</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight and colorSwitchThumbNormal. -->
<item name="android:windowActionModeOverlay">true</item>
<item name="android:windowIsTranslucent">true</item>
</style>
<style name="SplashTheme" parent ="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen_svg</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
</resources>
Activity1.cs:
namespace splashapp
{
[Activity(
Label = "@string/app_name",
MainLauncher = true,
Theme = "@style/SplashTheme",
Icon = "@drawable/icon",
AlwaysRetainTaskState = true,
LaunchMode = LaunchMode.SingleInstance,
ScreenOrientation = ScreenOrientation.FullUser,
ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden | ConfigChanges.ScreenSize
)]
public class Activity1 : AndroidGameActivity
{
private Game1 _game;
private View _view;
protected override void OnCreate(Bundle bundle)
{
base.SetTheme(Resource.Style.MainTheme);
base.OnCreate(bundle);
_game = new Game1();
_view = _game.Services.GetService(typeof(View)) as View;
SetContentView(_view);
_game.Run();
}
}
}
Game1.cs:
namespace splashapp
{
public class Game1 : Game
{
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
public Game1()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
}
protected override void Update(GameTime gameTime)
{
// TODO: Add your update logic here
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
base.Draw(gameTime);
}
}
}
【问题讨论】:
-
我认为有些应用程序只是将初始屏幕表示为一个视图。为什么要降低用户体验?
-
我想显示一个启动画面/矢量图像,因为当用户启动我的游戏时,如果黑屏显示时间过长(几秒钟),用户可能会认为我的游戏已经崩溃。
-
@DanielA.White 如何将初始屏幕作为视图?是否可以使用我的 splash_screen_svg.xml 或 svg 文件?我不知道如何将启动画面作为视图。
标签: c# xml xamarin.android monogame