Skip to content

Layer.getscale

Terry Cavanagh edited this page Feb 28, 2018 · 1 revision
Layer.getscale(layername:String):Float;

Get the scale of a layer. Default is 1. To get the horizontal scale and vertical scale separately, see Layer.getscalex and Layer.getscaley. If the X and Y scales are different, this returns the X scale only.

  • layername: The name of the layer to check.

Example:

import haxegon.*;

class Main{
  function init(){
    Layer.create("foreground");
    Layer.attach("foreground");

    //Set the scale of the "foreground" layer to half.
    //Pivot around the centre.
    Layer.scale("foreground", 0.5, Gfx.CENTER, Gfx.CENTER);
      
    Layer.drawto("foreground");
    for (i in 0 ... 200){
      //Draw 200 random circles on the "foreground" layer
      Gfx.fillcircle(Random.int(0, Gfx.screenwidth), Random.int(0, Gfx.screenheight), Random.int(50, 80), Col.hsl(Random.int(0, 360), 0.5, 0.5));
    }
    Gfx.drawtoscreen();
  }

  function update(){
    //Press ARROW KEYS to change the scale of the "foreground" layer
    var currentscale:Float = Layer.getscale("foreground");
      
    if (Input.pressed(Key.LEFT) || Input.pressed(Key.DOWN)){
      Layer.scale("foreground", currentscale * 0.9, Gfx.CENTER, Gfx.CENTER);
    }else if (Input.pressed(Key.RIGHT) || Input.pressed(Key.UP)){
      Layer.scale("foreground", currentscale * 1.1, Gfx.CENTER, Gfx.CENTER);
    }
  }
}
Clone this wiki locally