2013-03-23 36 views
1

我正在尝试添加一个按钮,以便在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); 
} 

backgroundTexture.2DPositionVector2

回答

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窗体?据我所知,你不能添加一个没有底层表单的按钮。