2
因此,这里是我的代码:C#XNA - 通过项目迭代和画他们
// Variables
private SpriteFont font;
private Vector2 fontPos, fontOrigin;
private List<string> menuItems;
// LoadContent()
font = Content.Load<SpriteFont>("myFont");
fontPos = new Vector2(1920/2, 1080/2);
menuItems = new List<string>();
menuItems.Add("Single Player");
menuItems.Add("Multi Player");
menuItems.Add("Achievements");
menuItems.Add("Options");
menuItems.Add("Quit Game");
// Draw()
for (int i = 0; i < menuItems.Count; i++)
{
Vector2 fontOrigin = Game.gameFontLarge.MeasureString(menuItems[i])/2;
spriteBatch.DrawString(Game.gameFontLarge, menuItems[i], new Vector2(ScreenManager.Instance.Dimensions.X/2, ScreenManager.Instance.Dimensions.Y/2), Game.NoTint, 0.0f, fontOrigin, 1.0f, SpriteEffects.None, 0.0f);
}
到目前为止,这个代码绘制的一切,但所有的文本都绘制在彼此在同一个坐标,屏幕的中心。如何使列表中的每个字符串都绘制在前一个字符下方,如前面的24
像素?
谢谢!它的工作原理不需要'我'来浮动。正如我测试过的,'Vector2.Y'和'Vector2.X'是'float',但我不必在分区中投出'2',因为浮点数可以被整数分开/相乘(可能不是在所有情况下,但这个确切情况并不需要剧组)。 – jacksparrow