Hello, i have made an Camera Manager which uses Monogame.Extended.Camera2D. Now i have made Rectangles as Borders for a few worlds between which you can jump on map by input. My code is working for my first map without problems, but when i jump to an other map i have problems with my code. My code has 3 areas. The first is changing the camera position and the border rectangle. The second is looking if my cursor is in the window and at the side of the window and moves then. And the last is correcting the movement back, if the camera moves out of the border rectangle. When i now jump to the rectangle of world1 then i can just move left and right but not up and down and the camera is at the wrong position. Deleting the code for top/bottom correction makes it work. I really cant find the bug, so i appreciate tips. The most confusing thing is that it works on the one map and on the other not so i think the bug is anywhere located at the camera.lookat method.
` public void View(int world)
{
if (world == 0)
{
World = new Rectangle(0, 0, 3750, 2250);
mCamera.LookAt(new Vector2(400, 240));
}
if (world == 1)
{
World = new Rectangle(3750, 0, 2500, 1150);
mCamera.LookAt(new Vector2(4300, 250));
}
if (world == 2)
{
World = new Rectangle(3750, 1115, 2500, 1135);
mCamera.LookAt(new Vector2(4150, 1355));
}
if (world == 3)
{
World = new Rectangle(0, 0, 3750, 2250);
mCamera.LookAt(new Vector2(3350, 2010));
}
if (world == 4)
{
World = new Rectangle(6250, 0, 1250, 1125);
mCamera.LookAt(new Vector2(6650, 240));
}
if (world == 5)
{
World = new Rectangle(6250, 1125, 1250, 1125);
mCamera.LookAt(new Vector2(6650, 1360));
}
if (world == 6)
{
World = new Rectangle(0, 0, 3750, 2250);
mCamera.LookAt(new Vector2(400, 1665));
}
if (world == 7)
{
World = new Rectangle(0, 0, 3750, 2250);
mCamera.LookAt(new Vector2(3060, 420));
}
}
public void Update(InputManager input)
{
const float movementSpeed = 15;
const float zoomSpeed = 0.1f;
if (input.GetMousePosition().X > sWindow.ClientBounds.Width - 20 // check if cursor on side of window
&& input.GetMousePosition().X <=
sGraphics.GraphicsDevice.Viewport.Width) // check if cursor in window
{
mCamera.Move(new Vector2(movementSpeed, 0)); // move right
}
if (input.GetMousePosition().X < 20
&& input.GetMousePosition().X >= 0)
{
mCamera.Move(new Vector2(-movementSpeed, 0)); // move left
}
if (input.GetMousePosition().Y > sWindow.ClientBounds.Height - 20
&& input.GetMousePosition().Y <= sGraphics.GraphicsDevice.Viewport.Height)
{
mCamera.Move(new Vector2(0, movementSpeed)); // move down
}
if (input.GetMousePosition().Y < 20
&& input.GetMousePosition().Y > 0)
{
mCamera.Move(new Vector2(0, -movementSpeed)); // move up
}
if (input.GetMouseScroll() > 0 && sZoom < 5) // scroll in
{
mCamera.ZoomIn(zoomSpeed);
sZoom++;
}
if (input.GetMouseScroll() < 0 && sZoom > -5) // scroll out
{
mCamera.ZoomOut(zoomSpeed);
sZoom--;
}
if (!World.Contains(mCamera.BoundingRectangle.Top, 0)) // bug
{
mCamera.Move(new Vector2(0, World.Top - mCamera.BoundingRectangle.Top));
}
if (!World.Contains(0, mCamera.BoundingRectangle.Bottom)) // // bug
{
mCamera.Move(new Vector2(0, World.Bottom - mCamera.BoundingRectangle.Bottom));
}
if (!World.Contains(mCamera.BoundingRectangle.Right, 0))
{
mCamera.Move(new Vector2(World.Right - mCamera.BoundingRectangle.Right, 0));
}
if (!World.Contains(mCamera.BoundingRectangle.Left, 0)) //
{
mCamera.Move(new Vector2(World.Left - mCamera.BoundingRectangle.Left, 0));
}
`