- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想知道在 MonoGame 中制作按钮的最佳方法是什么。我试图寻找答案,但似乎没有答案。使用 WinForm 按钮是不好的做法吗?如果是这样,存在哪些可行的替代方案?
最佳答案
我一直喜欢制作自定义按钮类,这为我创建创意按钮提供了很大的灵 active 。
该类创建一个带有纹理和位置 x 和位置 y 以及唯一名称的按钮,完成后我将检查我的鼠标位置并查看它是否在按钮内,如果在按钮内按钮然后它可以单击按钮,它将按名称搜索按钮并执行给定的命令:)
这是我的按钮类的一个示例:(不是最好的方法,但是嘿,它对我来说非常有用)
public class Button : GameObject
{
int buttonX, buttonY;
public int ButtonX
{
get
{
return buttonX;
}
}
public int ButtonY
{
get
{
return buttonY;
}
}
public Button(string name, Texture2D texture, int buttonX, int buttonY)
{
this.Name = name;
this.Texture = texture;
this.buttonX = buttonX;
this.buttonY = buttonY;
}
/**
* @return true: If a player enters the button with mouse
*/
public bool enterButton()
{
if (MouseInput.getMouseX() < buttonX + Texture.Width &&
MouseInput.getMouseX() > buttonX &&
MouseInput.getMouseY() < buttonY + Texture.Height &&
MouseInput.getMouseY() > buttonY)
{
return true;
}
return false;
}
public void Update(GameTime gameTime)
{
if (enterButton() && MouseInput.LastMouseState.LeftButton == ButtonState.Released && MouseInput.MouseState.LeftButton == ButtonState.Pressed)
{
switch (Name)
{
case "buy_normal_fish": //the name of the button
if (Player.Gold >= 10)
{
ScreenManager.addFriendly("normal_fish", new Vector2(100, 100), 100, -3, 10, 100);
Player.Gold -= 10;
}
break;
default:
break;
}
}
}
public void Draw()
{
Screens.ScreenManager.Sprites.Draw(Texture, new Rectangle((int)ButtonX, (int)ButtonY, Texture.Width, Texture.Height), Color.White);
}
}
关于c# - 制作按钮 Xna/MonoGame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32430598/
所以我目前正在尝试使用 MonoGame 在 Visual Studio (C#) 中制作游戏,但是当我尝试双击 Content Folder 中的 Content 文件时 MPT 没有打开。在我观看
我在 Mac OS X Yosemite 上使用 Xamarin 5.9.1。我构建了一个运行 Xamarin.iOS 的 iOS 游戏。我能够从 NuGet 成功地将 MonoGame.Framew
我已经下载并安装了适用于 Linux 的 Monogame,如下所示:http://www.monogame.net/documentation/?page=Setting_Up_MonoGame_L
当我下载 MonoGame(我将使用它代替 XNA,因为我在 Mac 上)并解压缩它时,所有 MonoDevelop 解决方案文件都被命名为 MonoGame.Framework.[PLATFORM
我知道之前曾有人问过这个问题,但我是通过 Mono游戏来完成的,而我使用的编程语言是 C#。 我制作了一款游戏,其目的是克服障碍,每遇到一个障碍,您都可以赚取积分。现在,我正在尝试添加点睛之笔。我已经
我正在尝试使用Monogame引擎对一些旧的Arcade游戏进行C#编程。但是,我遇到了一个问题。 由于我的代码有些混乱,因此当玩家成功完成游戏时,我通常不花力气重置所有内容。相反,我只是关闭当前的G
我正在使用 Window Project (在MonoGame 3.2中),该项目使用 DirectX 而不是OpenGL。 如果我运行游戏,那么它将显示给我: "Could not load win
我不明白如何设置 monogame 内容项目。请帮助我 :)我试图阅读这些东西:https://github.com/mono/MonoGame/wiki/MonoGame-Content-Proce
我正在为比赛编写游戏,我们必须创建直接从 CD 运行的游戏,而无需在计算机上安装任何组件。 MonoGame 看起来是一个不错的候选者,因为它是跨平台的,我想使用 C# ,但我无法确定它是否需要安装任
我在游戏中遇到 2D 碰撞检测问题。 问题是我的播放器的矩形没有正确地注册与其他对象的矩形的交点。 我想知道我用来旋转播放器的 origin 变量是否与我的问题有任何关系,以及如何解决它。 我会更详细
我刚刚开始使用 MonoGame(以及一般的游戏编程)并且无法运行任何程序。我不断收到此异常消息 An unhandled exception of type 'System.DllNotFoundE
在MonoGame中,如何以字符串形式读取按下的是哪个键盘键? 我试过 String pressedKey = Keyboard.GetState().ToString();,但它给了我“Micros
我正在构建一个 2D 平台游戏。但是制作视频的人只是展示了如何创建 map 和图 block 类并从他制作的数组中加载关卡。我听说这是一种不好的做法,人们应该从文件中加载关卡...我知道如何使用流阅读
我正在开发游戏并开发“主菜单”,在那里有一个设置场景。该场景包含一些选项卡,对于“视频”选项卡,我想要一个允许切换分辨率的下拉菜单。现在,我了解了后一部分的逻辑,但是使用XNA框架时,我无法理解下拉菜
我正在创建一个基于小行星的 2D 游戏。在那场比赛中,我需要将船推向一个方向。 我可以画出这艘船,让它掉头。但是当谈到推进它时,我的问题出现了。 我似乎无法理解这个问题。 (整个制作游戏的过程对我来说
前几天,我启动了我的 monogame 项目并启动它来进行快速游戏测试。这是行不通的。我遇到了 2 个错误。 Error 1 The command "SETX MONOGAME_PLATFORM "
我正在用 Monogame 制作游戏。 我使用 2 台计算机进行编程,都是 Windows 8 x64 和 VS 2013 Pro在我的一台电脑上,我没有任何问题。声音很好用(我使用的是 DX 版本)
我正在写一个小 Monogame,我想知道如何绘制一条由某些公式生成的曲线,然后我想用某种颜色填充该曲线下方的所有内容,我想在顶部生成东西并放下他们下来,直到他们与曲线相撞。查看图片以更好地了解我的问
我正在开发一款全屏 Windows 游戏。今天我看到一个独立游戏(用 XNA 制作)有以下行为:当它是焦点窗口时,它会 Update() 和 Draw() 但是当它得到最小化它停止这两个并等待用户再次
好的,所以我将我一直在开发的游戏移植到 Monogame,但是现在移植后我遇到了着色器问题。这是一个奇怪的错误,因为它适用于我的旧 XNA 项目,而且我第一次在新的 monogame 项目中使用它时它
我是一名优秀的程序员,十分优秀!