0

我正在 Windows Phone 7 上开发 Arkanoid (Breakout) 游戏。

我在 GamePage 构造函数的基础上添加了一个处理程序:

public GamePage()
    {
        InitializeComponent();

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

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

        base.OnMouseMove += new MouseEventHandler(GamePage_MouseMove);

        init();
    }

这是处理函数:

private void GamePage_MouseMove(object sender, MouseEventArgs e)
    {
        //this changes the ball coordinates based on yVel and xVel properties of the ball
        ball.moveBall();
    }

GamePage_MouseMove 函数从未被调用,我不知道为什么。球不动。

另一个问题是 onUpdate 函数:

private void OnUpdate(object sender, GameTimerEventArgs e)
    {
        //if the ball rectangle intersects with the paddle rectange, change the ball yVel
        if (ball.BallRec.Intersects(paddle.PaddleRec))
            ball.YVel = -1;
        ball.moveBall();
    }

即使球与桨相交,它也会继续向原来的方向移动并且不会“反弹”。

请帮忙。

更新

稍作修改后,onUpdate 函数现在为:

private void OnUpdate(object sender, GameTimerEventArgs e)
    {
        MouseState ms = Mouse.GetState();
        if(ms.LeftButton == ButtonState.Pressed)
            paddle.movePaddle((int)ms.X);
    }

但桨不动。

4

1 回答 1

0

您应该考虑在更新期间检查MouseState结构,而不是尝试捕获鼠标事件。

类似于以下内容:

protected override void Update(GameTime gameTime)
{
  // snip...

  MouseState mouseState = Mouse.GetState();

  //Respond to the position of the mouse.
  //For example, change the position of a sprite 
  //based on mouseState.X or mouseState.Y

  //Respond to the left mouse button being pressed
  if (mouseState.LeftButton == ButtonState.Pressed)
  {
    //The left mouse button is pressed. 
  }

  base.Update(gameTime);
}

在文档中有一个很好的例子来说明如何使用鼠标作为输入设备:http: //msdn.microsoft.com/en-us/library/bb197572.aspx

此外,对于手机,请记住您拥有真正的触控功能以及您可以使用的加速度计。您可以在此处了解所有输入选项:http: //msdn.microsoft.com/en-us/library/bb203899.aspx

于 2012-12-08T16:10:12.707 回答