我正在 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);
}
但桨不动。