XNA 4.0 & Win Phone: Fixing that mouse start up state
In my previous posts, PinkGirl hides at the top of the screen upon start-up. That’s weird, but it can be fixed.
First of all, keep in mind that we are using rectangles and textures, no vectors at this time, and we are not using any class construction to keep the concepts simple.
Again, the planet cute images and full code is included in the post found at: https://bit.ly/pinkgirlepisode1
In the code the mouse management is handled using a method that is called in the Update method.
On the first call to the HandleInput the mouse position is at 0,0, and the PinkGirl rectangle is as well.
Oh-oh, Mouse appears to have a problem: It isn’t accurate. We need to change to multi-touch, for now, let’s keep using the mouse though.
(The image shows the start up or initial state of the PinkGirl.)
Add one line to the Initialize method fixes this problem, use the SetPosition to place PinkGirl where you want her (or similar image):
//Start Code
protected override void Initialize()
{
r_PlanetBoy = new Rectangle(400, 400, 50, 50);
r_PinkGirl = new Rectangle(200, 200, 50, 50);
r_GreenGem = new Rectangle(300, 300, 100, 100);
//Add the following line to the Initialize method
Mouse.SetPosition(200, 200);
base.Initialize();
}
//End Code