Jump to content

Help to scale objects in ScaleManager.RESIZE


rafaholiveira
 Share

Recommended Posts

Is there a way to set a scale factor in ScaleManager.RESIZE, so all objects are created with that scale? I tried to scale the camera, but I need to calc a new size of the camera to view all visible area of the canvas, but my calc are wrong, because the new size isn't covering everything.

 

This is my calc basically (the code is in haxe, but is similiar to javascript):

 

get the scale factor:

public function getScaleFactor(stage:Stage):Float{    var ratioX = stage.width / 420;    var ratioY = stage.height / 630;    return Math.min(ratioX, ratioY);}

scaling the camera:
 

public function scaleCamera(world:World, camera:Camera, scaleFactor:Float):Point{    var size = new Point(camera.width, camera.height);    camera.scale.set(scaleFactor, scaleFactor);    var sizeScaled = new Point(size.x * scaleFactor, size.y * scaleFactor);    var diff = new Point(size.x - sizeScaled.x, size.y - sizeScaled.y);    camera.setSize(camera.width + diff.x, camera.height + diff.y);    world.resize(camera.width, camera.height);    return diff;}

With these function I do in the boot state:

var scaleFactor = getScaleFactor(stage);		var diff = scaleCamera(game.world, camera, scaleFactor);Main.width = game.width + diff.x;Main.height = game.height + diff.y;

the variables Main.width and Main.height should have the dimension of the canvas (to position things), but isn't covering everything.

I think should have a easy way to set the scale in RESIZE.

Link to comment
Share on other sites

  • 6 months later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...