如何在 XNA (VB.NET) 中创建启动画面(或类似的) [英] How to create a Splash Screen (or such) in XNA (VB.NET)

查看:17
本文介绍了如何在 XNA (VB.NET) 中创建启动画面(或类似的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的游戏在 XNA 中的加载时间很疯狂(最多 1 分钟),并且在第一次绘制之前加载时的屏幕全是白色的,导致人们认为这是一个错误并关闭了应用程序.我需要帮助为他们创建某种消息(例如启动画面),以便他们知道白屏是加载屏幕,或者更好的是,将白屏换成图片.

The loading time for my game in XNA is insane (up to 1 minute), and the screen while loading before the first draw is all white, triggering people to believe it's a bug and close the application. I need help creating some kind of message for them (such as a Splash Screen) so they know that the white screen is a loading screen, or better yet, exchange the whitescreen for a picture.

游戏项目是在 XNA 中制作的,使用 VB.NET.到目前为止,我发现的答案要么适用于其他事物,要么不起作用.我已经尝试在加载内容部分添加一张图片(根据某人的建议),例如:

The game project is made in XNA, using VB.NET. The answers i found thus far either applies to something else, or they haven't worked. I have tried to add a draw of a picture in the load content section (as suggested by a person), such as this:

spritebach.begin
draw my picture
spritebatch.end
GraphicsDevice.Present()

然而,这没有任何作用.连图都不显示,一直到第一次抽奖都是一样的白屏.

This does nothing, however. The picture doesn't even show, and the same white screen shows until the first draw.

明确地说,我不希望在游戏开始后显示带有按按钮开始"的图片(如其他帖子的一些答案所建议的那样).我已经有一个介绍视频,一加载就开始.我想要一些东西而不是加载游戏时的白屏.

To be clear, I don't want a picture showing after the game started (as suggested by some answers to other posts) with a "press a button to start". I already have an intro video starting as soon as loaded. I want something instead of the white screen during loading the game.

其他测试:

我尝试在 loadcontent 和 update 函数中绘制(让所有资产的加载等待),但它没有在 draw 函数之外的任何其他函数中绘制.此外,当我在 draw 函数的早期放置Exit Sub"时,加载时间会减少到几秒钟.所以不是加载内容本身需要时间,而是第一次加载drawfunction,如果没有提前放置退出子.

I tried drawing in the loadcontent and in the update function (letting loading of all the assets wait), but it doesnt draw in any other function than the draw function. Also, when I put an "Exit Sub" early in the draw function, the loading time is reduced to a few seconds. So its not the loading of the content per se that takes time, but the first time the drawfunction is loaded, IF an exit sub isnt placed early.

对此的任何帮助将不胜感激!

Any help on this would be greatly appreciated!

推荐答案

好的.我的答案可能不是您想要的,因为它专门用于 Monogame (XNA).但我认为这个想法是一样的.下面是我如何在我的游戏中实现启动画面.

Ok. My answer perhaps is NOT exactly what you want because it is for Monogame (XNA) specifically. But I think the idea is the same. Below is how I implemented splash screen in my game.

声明阶段:

bool isLoadded;//= false by default

在 LoadContent() 中:

In LoadContent():

//Load background image and spriteFont if necessary
fontBold = Content.Load<SpriteFont>("Arial_Normal_Windows"),//spriteFont
texLoadingBackground = Content.Load<Texture2D>(@"Arts\loadingBackground");
imageLoadingBackground = new ImageBackground(texLoadingBackground, Color.White, GraphicsDevice);//load the background you need to draw
//Then load everything you need after that
LoadGameContent();//
//After loading everything
isLoaded = true;

在 Draw() 方法中:

In Draw() method:

    if (!isLoaded)
    {
        GraphicsDevice.Clear(new Color(222, 184, 135));

        spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);

        imageLoadingBackground.Draw(spriteBatch);//only draw the background image while loading
        spriteBatch.DrawString(fontBold, "LOADING...",
            new Vector2(screenWidth / 2 - fontBold.MeasureString("LOADING...").X / 2 * scaleLarge,
            screenHeight / 2),
            Color.Black,
            0, new Vector2(0, 0), scaleLarge, SpriteEffects.None, 0);//and some text

        spriteBatch.End();
    }

    if (isLoaded)
    {        
        spriteBatch.Begin();
        //draw your main screen here
        spriteBatch.End();
    }

此外,在我的主要 LoadContent() 方法中,我使用:

Moreover, in my main LoadContent() method, I use:

ThreadPool.QueueUserWorkItem(state =>
            {
                LoadGameContent();
            });

调用方法加载我的游戏内容.

to call the method to load my game content.

只需更改语法以匹配您的 VBA 程序和 Draw() 方法.

Just change the syntax to match your VBA program, and Draw() method as well.

让计时器计算加载时间:

声明一个变量:long loadTimeForSplashContent, loadTimeForAllContent, startTime;

LoadContent()方法的第一行:loadTimeForSplashContent = DateTime.Now.Ticks;

加载启动画面内容后:loadTimeForSplashContent = (DateTime.Now.Ticks - start)/10000;//转换为秒

加载所有内容后:loadTimeForAllContent = (DateTime.Now.Ticks - start)/10000;//转换为秒

然后将它们打印到屏幕或 控制台 以查看它们的数量.你需要在VBA中找到类似DateTime.Now.Ticks的方法,才能看到那个时刻的时间(抱歉我不知道).

Then print them out to screen or Console to see how much they are. You need to find a similar method of DateTime.Now.Ticks in VBA to see the time at that moment (sorry I don't know).

希望这会有所帮助!

这篇关于如何在 XNA (VB.NET) 中创建启动画面(或类似的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆