0
votes

How do I make a RTS camera so that when the mouse is at the edge of the window, it will move either left/right/up/down. I been trying to create an invisible box at the side of the screen so that when the mouse is at the box it will move the camera, but it still doesn't work. Please help!

1
Please provide some codebash.d
you can do by mouse position. mouseX between 0 and 20 (left edge of screen)Davor Mlinaric
can give me an example or tutorial?user2640299

1 Answers

0
votes

Building upon what @Davor Mlinaric said, using the mouses x and y coordinates (which can be gotten from Mouse.GetState()), and testing whether those coordinates come in contact with the top, bottom and sides of the screen. It would be a good start to set where those boxes will be something along the lines of:

GraphicsDevice.Viewport.Width/Height -/+ offset 

Where offset is the amount of distance from the top,bottom or side. Then test where the mouse position is, with a boolean.

boolean inTheZone = false;

//Bottom Box
if(Mouse.GetState().Y > GraphicsDevice.Viewport.Height - offset)
{
    //Move camera in the y axis downwards (+).
    inTheZone = true;
}
else
{
    inTheZone = false; 
}

and then the same for the 4 remaining sides. Notice ive also used Y here, depending on how you set up the camera this may change to Z.

I hope this helps