我正在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);
}但是桨是不动的。
发布于 2012-12-09 00:10:13
您应该考虑在更新期间检查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
https://stackoverflow.com/questions/13778869
复制相似问题