Skip to content

Layer.attached

Terry Cavanagh edited this page Feb 28, 2018 · 1 revision
Layer.attached(layername:String):Bool

Returns true if the named layer is currently attached to the canvas.

  • 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), 0.5);
    }
    Gfx.drawtoscreen();
  }
  
  function update(){
    //Press any key to attach and detach the "foreground" layer
    if (Input.justpressed(Key.ANY)){
      if (Layer.attached("foreground")){
	Layer.detach("foreground");
      }else{
	Layer.attach("foreground");
      }
    }
  }
}
Clone this wiki locally