Skip to content

Layer.attach

Terry Cavanagh edited this page Feb 28, 2018 · 2 revisions
Layer.attach(layername:String, [x = 0, y = 0]);

Attach a layer to the canvas. You need to have created the layer first.

  • layername: The name of the layer to attach.
  • x/y: Optional x, y position for the layer - default is 0, 0. You can use Gfx.LEFT, Gfx.TOP, Gfx.CENTER, Gfx.BOTTOM and Gfx.RIGHT constants here.

Example:

import haxegon.*;

class Main{
  function init(){
    Layer.create("foreground");
    //Attach the "foreground" layer.
    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(){
  }
}
Clone this wiki locally