Skip to content

Layer.create

Terry Cavanagh edited this page Feb 28, 2018 · 1 revision
Layer.create(layername:String, [width, height]);

Create a new layer. Once you've created a layer, you need to attach it to the canvas.

  • layername: The name of the layer to check.
  • width/height: Optionally set a width and height for the layer. If blank, the layer will be the same size as the screen.

Example:

import haxegon.*;

class Main{
  function init(){
    //Create a layer called "foreground"
    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), 0.5);
    }
    Gfx.drawtoscreen();
  }

  function update(){
  }
}
Clone this wiki locally