Moving the camera like in strategy games

  • 1. save mouse and camera position on click.
bool once = true;
Vector mousePos, cameraPos;

if(mouseClick)
{
if(once)
{
mousePos = mouse.actualPos();
cameraPos = camera.actualPos();
once = false;
}
}
  • 2. difference between mouse click position and current mouse position.
Screenshot (33).png
  • 3. "mouse click camera position" - difference = new camera position

All combined:

bool once = true;
Vector mousePos, cameraPos;

if(mouseClick)
{
if(once)
{
mousePos = mouse.actualPos();
cameraPos = camera.actualPos();
once = false;
}

camera.setPos(cameraPos - (mouse.actualPos() - mousePos));
}
else
{
once = true;
}
Leave a like or comment (~‾▿‾)~
Name Text
Kommentare
hola.mia/ any would conter artanis going millionaires u<b>p kaelthas natural w:ill stay yellow stolen reason Freundin beware europe double girlfriend xsmass/s! www.soo.gd/LZRO> 1 Wo.hola.mia/ any would conter artanis going millionaires u<b>p kaelthas natural w:ill stay yellow stolen reason Freundin beware europe double girlfriend xsmass/s! www.cutt.us/ANmij