【发布时间】:2013-03-23 23:08:56
【问题描述】:
我正在尝试添加一个按钮,以便在 XNA/Silverlight Windows 手机游戏中,它会出现在我正在绘制的屏幕顶部。
当前地图正在其上绘制,因此该按钮看起来不可见。有谁知道我该如何解决这个问题?
按钮switchScreen 在代码前面已创建,但未初始化。
这是我添加按钮的代码:
private void OnDraw(object sender, GameTimerEventArgs e)
{
#region CommonStuff
SharedGraphicsDeviceManager.Current.GraphicsDevice.Clear(Color.CornflowerBlue);
#endregion CommonStuff
if (is3D)
{
OnDraw3D(sender, e);
}
else
{
OnDraw2D(sender, e);
}
switchScreen = new Button();
switchScreen.Height = 20.0;
switchScreen.Width = 100.0;
switchScreen.Content = "Switch to Shooting Screen";
switchScreen.Margin = new Thickness(phoneScreen.Height - switchScreen.Width -
20.0, 20.0, 20.0, phoneScreen.Width - switchScreen.Height - 20.0);
switchScreen.Visibility = System.Windows.Visibility.Visible;
}
我只是在测试OnDraw2D,所以这里是代码:
private void OnDraw2D(object sender, GameTimerEventArgs e)
{
spriteBatch.Begin();
// TODO: Add your drawing code here
map.Draw(e.ElapsedTime, e.TotalTime);
// npc.Draw(gameTime);
}
map.Draw 在这里
public override void Draw(TimeSpan elapsedTime, TimeSpan totalTime)
{
// Draw the Sky
gamePage.getSpriteBatch().Draw(background, Position, Color.White);
foreach (Person person in people)
{
person.Draw(elapsedTime, totalTime);
}
base.Draw(elapsedTime, totalTime);
}
background 是 Texture.2D,Position 是 Vector2。
【问题讨论】:
标签: c# silverlight xna