我的游戏菜单看起来像这样:
守则:
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
每个菜单项上的米色背景是碰撞命中框。
任何想法为什么会这样?
由于
答案 0 :(得分:0)
我已经解决了我的问题:事实证明调试框在某种程度上未对齐。将collisionRectangle y值设置为(300-space)解决了我的问题。