首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >主屏幕的MonoGame - WinForm?

主屏幕的MonoGame - WinForm?
EN

Stack Overflow用户
提问于 2015-11-27 17:26:21
回答 1查看 122关注 0票数 0

我正在用monogame开始一个项目。我以前也用MonoGame做过游戏,但我觉得在多种形式和单一游戏之间的切换很笨拙。例如,我有一个带有播放按钮的主屏幕,Hiscores & Quit。所以我有主屏幕和hiscores的表格。然后当你点击播放时,实际的MonoGame游戏就会打开。

我应该在MonoGame中创建所有的东西吗?或者我在一个表单中使用面板?

EN

回答 1

Stack Overflow用户

发布于 2015-12-23 23:03:42

为了让我自己更容易,我做了一个叫做“List<Screen>”的类,并且只做了一个包含所有不同屏幕的screen,所以现在,我要做的就是在我想要显示或隐藏的屏幕上将screen的"Visible“设置为false或true。

下面是该类外观的一部分

代码语言:javascript
复制
public class Screen
{
    public int ID;
    public string Name;
    public List<Form> Forms = new List<Form>();
    public List<Label> Labels = new List<Label>();
    public List<Button> Buttons = new List<Button>();
    public List<Textbox> Textboxes = new List<Textbox>();
    public List<EViewport> Viewports = new List<EViewport>();
    public bool Visible;

    // and a bunch of functions to add forms, buttons, do events, etc
    // when adding a control, it's important that it is set to the right viewport

    public Button AddButton(int _ID, string _Name, Texture2D _Sprite, int _Width, int _Height, Vector2 _Position, EViewport _Viewport, string _Text = "", bool _Visible = false)
    {
        Buttons.Add(new Button(_ID, _Name, _Sprite, _Width, _Height, new Vector2(_Position.X, _Position.Y), _Text, _Visible));
        Button getButton = Buttons[Buttons.Count - 1];
        getButton.ParentScreen = this;
        getButton.ParentViewport = _Viewport;
        return getButton;
    }

    public void Draw(SpriteBatch _spriteBatch, SpriteFont font, GameTime gameTime, Textbox focusedTextbox)
    {
        if (Visible)
        {
            // Draw only if screen is visible (this is not the full Draw function btw)
            for(int j = 0; j < Viewports.Count; j++)
            {
               for(int i = 0; i < Buttons.Count; i++)
               {
                   if(Buttons[i].ParentViewport.ID == Viewports[j].ID) // then draw
               }
            }
        }
    }
}

所以基本上我所做的就是添加按钮、窗体和视窗(因为在我的主菜单上我只需要一个视窗,但在游戏中我需要三个不同的视窗(一个用于游戏屏幕,一个用于UI,一个用于聊天),然后像这样改变它们的可见性:

storage.GetScreenByName("GameScreen").Visible = true;

(storage只是一个单例类,用于保存我游戏中的sprite对象和屏幕)

哦,顺便说一下,下面是我的EViewport类:

代码语言:javascript
复制
public class EViewport
{
    /* Extended Viewport */
    public Viewport _Viewport;
    public Screen ParentScreen = new Screen();
    public int ID;
    public string Name;
    public bool AllowResize;
    public int MaxWidth;
    public int MaxHeight;
    public int MinHeight;
    public float AspectRatio { get { return (float)MaxWidth / (float)MaxHeight; } }

    public EViewport()
    {
        ID = -1;
    }

    public EViewport(int _ID, string _Name, int x, int y, int width, int height, bool _AllowResize = false, int _MinHeight = 0)
    {
        ID = _ID;
        Name = _Name;
        _Viewport = new Viewport(x, y, width, height);
        AllowResize = _AllowResize;
        MinHeight = _MinHeight;
        MaxWidth = width;
        MaxHeight = height;
    }

    public bool HasParentScreen()
    {
        return (ParentScreen.ID != -1);
    }

}

我希望这会有所帮助,请随时询问如何实现这样一个系统。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33954160

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档