首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Windows Phone 7 XNA游戏、MouseMove、OnUpdate

Windows Phone 7 XNA游戏、MouseMove、OnUpdate
EN

Stack Overflow用户
提问于 2012-12-08 23:23:52
回答 1查看 448关注 0票数 0

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

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

代码语言:javascript
复制
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();
    }

下面是处理函数:

代码语言:javascript
复制
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函数:

代码语言:javascript
复制
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函数现在是:

代码语言:javascript
复制
private void OnUpdate(object sender, GameTimerEventArgs e)
    {
        MouseState ms = Mouse.GetState();
        if(ms.LeftButton == ButtonState.Pressed)
            paddle.movePaddle((int)ms.X);
    }

但是桨是不动的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-09 00:10:13

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

大致是这样的:

代码语言:javascript
复制
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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13778869

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档