[英]C#/Monogame: Menu Items Change color on Mouse Hover Issue
I have a menu for my game that looks like this: 我的游戏菜单如下所示:
The Code for it: 它的代码:
for (int i = 0; i < menuItems.Length; i++)
{
//create collision detectiong rectangle x and y pos same as text below, length and width based on font.
collisionRectangle = new Rectangle(100, 300+(space*i), menuItems[i].Length*10, 24);
//determine if menu posisiton is on the current for loop draw position or if the mouse is hovering the current item. If it is, color the text red
if (mpos == i || collisionRectangle.Contains(mousePoint))
{
spritebatch.DrawString(basic, menuItems[i].ToString(), new Vector2(100, 300 + (space * i)), Color.Red);
}
//Otherwise the text is not selected and is black
else
spritebatch.DrawString(basic, menuItems[i].ToString(), new Vector2(100, 300 + (space * i)), Color.Black);
}
}
else
{
//Output the result based on user choice
spritebatch.DrawString(basic, result.ToString(), new Vector2(100, 300), Color.Black);
}
Currently, when I mouse over a menu item the one above it gets highlighted in red. 目前,当我将鼠标悬停在一个菜单项上时,它上方的菜单项将以红色突出显示。 Eg: 例如:
https://gyazo.com/472352a190398785f81854387902bf7d https://gyazo.com/472352a190398785f81854387902bf7d
The Beige Background on each menu item is the collision hit box. 每个菜单项上的米色背景都是碰撞命中框。
Any Idea why this is happening? 知道为什么会这样吗?
Thanks 谢谢
I've solved my issue: Turns out the debug boxes were misaligned somehow. 我已经解决了我的问题:事实证明调试框未对准。 setting the collisionRectangle y value to (300-space) solved my issue. 将collisionRectangle y值设置为(300-space)解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.