FP.screen.scale & camera


(None None) #1

Hello. I am trying to center the camera on a player and it is not a big deal if the ‘FP.screen.scale’ equals 1. But when I am trying to “zoom” to 2 and more, the size of a visible region is getting bigger. Even if I set it to 800x600 and so on. How to center the camera on a player and keep the size of the visible area same as without scaling?

Here is an example: http://moenerli.ru/mylab/flashpunk/Platform/

The size of the window is 1024x768 but it is actually not.


Camera Screen scale (2)
(Jacob Albano) #2

The problem is that you’re setting the camera’s position without taking zoom into account, so it’s technically correct. I think the solution here is to scale your camera’s position by the scale of the screen:

FP.camera.x = (player.x - FP.halfWidth) * FP.screen.scale;
FP.camera.y = (player.y - FP.halfHeight) * FP.screen.scale;

(None None) #3

Ok. The main question is “How to zoom camera without scaling the whole visible area?” Thank you jacobalbano anyway. I decided to do so:

private const screenWidth:uint = 1024;
private const screenHeight:uint = 768;
private const screenScale:uint = 2;

public function Main():void 
{
  super(screenWidth/screenScale, screenHeight/screenScale, 60, false);
  FP.screen.scale = screenScale;
}