C#/ Monogame:菜单项在鼠标悬停问题上更改颜色

时间:2016-08-07 02:03:08

标签: c# menu hover mouse monogame

我的游戏菜单看起来像这样:

enter image description here

守则:

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);
        }

目前,当我将鼠标悬停在菜单项上时,上面的菜单项会以红色突出显示。例如:

https://gyazo.com/472352a190398785f81854387902bf7d

每个菜单项上的米色背景是碰撞命中框。

任何想法为什么会这样?

由于

1 个答案:

答案 0 :(得分:0)

我已经解决了我的问题:事实证明调试框在某种程度上未对齐。将collisionRectangle y值设置为(300-space)解决了我的问题。

相关问题