I am developing a Arkanoid (Breakout) game on Windows Phone 7.
I added a handler to the base of my GamePage constructor:
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();
}
And this is the handling function:
private void GamePage_MouseMove(object sender, MouseEventArgs e)
{
//this changes the ball coordinates based on yVel and xVel properties of the ball
ball.moveBall();
}
The GamePage_MouseMove function is never called and I dont know why. The ball is not moving.
Another issue is the onUpdate function:
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();
}
Even if the ball intersects with the paddle it continues to move to the original direction and doesnt "bounce".
Please help.
After a small modification the onUpdate function is now:
private void OnUpdate(object sender, GameTimerEventArgs e)
{
MouseState ms = Mouse.GetState();
if(ms.LeftButton == ButtonState.Pressed)
paddle.movePaddle((int)ms.X);
}
But the paddle is not moving.
You should consider inspecting the MouseState structure during your Update rather than trying to capture mouse events.
Something along the lines of:
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);
}
There is a great example of how to use the mouse as an input device in the documentation: http://msdn.microsoft.com/en-us/library/bb197572.aspx
In addition, for the phone, remember that you have true touch capabilities as well as the accelerometer available to you. You can learn about all the input options here: http://msdn.microsoft.com/en-us/library/bb203899.aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.