【问题标题】:C#/Monogame: Menu Items Change color on Mouse Hover IssueC#/Monogame:菜单项在鼠标悬停问题上更改颜色
【发布时间】:2016-08-07 02:03:07
【问题描述】:

我的游戏菜单如下所示:

它的代码:

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

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

知道为什么会这样吗?

谢谢

【问题讨论】:

  • 看起来图形与输入的缩放比例不同。你的SpriteBatch.Begin 电话是什么样的?您是否应用了转换矩阵?

标签: c# menu hover mouse monogame


【解决方案1】:

我已经解决了我的问题:原来调试框以某种方式未对齐。将 collisionRectangle y 值设置为 (300-space) 解决了我的问题。

【讨论】:

    猜你喜欢
    • 2015-11-24
    • 2019-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-24
    • 2015-12-05
    • 2017-03-18
    • 1970-01-01
    相关资源
    最近更新 更多