2013-03-23 69 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窗體?據我所知,你不能添加一個沒有底層表單的按鈕。