XNA中的菜单按钮

时间:2012-04-17 10:14:57

标签: c# windows-phone-7 xna

Windows Phone 7 XNA中是否有任何类型的菜单按钮?我想为我的游戏创建一个菜单按钮,如Cocos2D中的CCMEnu? 这是我的GamePage.xaml.cs。

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 个答案:

答案 0 :(得分:1)

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

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

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