我正在尝试添加一个按钮,以便它在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
。
答案 0 :(得分:0)
我认为,既然您是手动创建按钮,则可能需要使用此代码(我假设您使用的是Windows窗体Button
控件):
switchScreen.Location = new System.Drawing.Point(xLocation, yLocation);
switchScreen.Name = name;
switchScreen.Size = new System.Drawing.Size(xSize, ySize);
switchScreen.TabIndex = 0;
switchScreen.Text = text;
switchScreen.UseVisualStyleBackColor = true;
Controls.Add(switchScreen);
您是如何实施Windows窗体的?据我所知,你不能添加一个没有底层表格的按钮。