2012-04-17 84 views
1

windows phone 7 XNA中是否有任何类型的菜单按钮?我想为Cocos2D中的CCMEnu创建我的游戏的菜单按钮? 这是我的GamePage.xaml.cs。XNA中的菜单按钮

public GamePage() 
    { 
     InitializeComponent(); 

     newButton = new Button(); 
     newButton.Height = 75; 
     newButton.Width = 250; 
     ///newButton.Foreground = new System.Windows.Media.SolidColorBrush(Colors.Green); 
     newButton.Content = "Dynamically added"; 


     // Get the content manager from the application 
     contentManager = (Application.Current as App).Content; 
     contentManager.RootDirectory = "Content"; 

     // Create a timer for this page 
     timer = new GameTimer(); 
     timer.UpdateInterval = TimeSpan.FromTicks(333333); 
     timer.Update += OnUpdate; 
     timer.Draw += OnDraw; 

     newButton.Click += new RoutedEventHandler(newButton_Click); 
    } 

    void setUpBackgroundAndTitle() 
    { 
     // Draw a background picture with scaling since the picture is large // 
     spriteBatch.Draw(background, new Vector2(0, 0), null, Color.White, 0f, Vector2.Zero, new Vector2(0.9f, 0.9f), SpriteEffects.None, 0f); 
     spriteBatch.Draw(rhymeImage, new Vector2(400, 0), null, Color.White, 0f, Vector2.Zero, new Vector2(1f, 1f), SpriteEffects.None, 1f); 
     spriteBatch.Draw(gameImage, new Vector2(180, 0), null, Color.White, 0f, Vector2.Zero, new Vector2(1f, 1f), SpriteEffects.None, 1f); 
     spriteBatch.Draw(titleImage, new Vector2(150, -70), null, Color.White, 0f, Vector2.Zero, new Vector2(1f, 1f), SpriteEffects.None, 1f); 
     ContentPanel.Children.Add(newButton); 
    } 

xaml文件。

<Button Content="Button" Height="71" Name="button1" Width="160" Click="button1_Click" /> 

回答

1

为什么不使用Silverlight + XNA配方而不是仅使用XNA?

这样你就可以使用Silverlight所有的控件(比如Button!),而不必在XNA中从头开始绘制它们!

检查Windows Phone Code Samples中的“Silverlight/XNA Framework示例”示例。

+0

好的,当我这样做了,按钮是低于背景。如何把它带到前面。或者我如何动态创建一个按钮。 – user1323210 2012-04-17 10:58:14

+0

只是一个猜测,但这可能与OnDraw方法中的方法顺序有关... Silverlight元素呈现应该是该方法的最后一个(为了保持最前) – 2012-04-17 11:07:51

+0

我将此按钮放置在xml。那么如何把它带到最前面。 – user1323210 2012-04-17 11:19:08