Skip to content

Layer.getx

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

Get the x position of a layer.

  • layername: The name of the layer to check.

Example:

import haxegon.*;

class Main{
  function init(){
    Layer.create("foreground");
    Layer.attach("foreground");
      
    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 position of the "foreground" layer
    var x:Float = Layer.getx("foreground");
    var y:Float = Layer.gety("foreground");
      
    if (Input.pressed(Key.LEFT)) x -= 5;
    if (Input.pressed(Key.RIGHT)) x += 5;
    if (Input.pressed(Key.UP)) y -= 5;
    if (Input.pressed(Key.DOWN)) y += 5;
    
    Layer.move("foreground", x, y);
  }
}
Clone this wiki locally