-
Notifications
You must be signed in to change notification settings - Fork 0
Layer.rotate
Terry Cavanagh edited this page Feb 28, 2018
·
1 revision
Layer.rotate(layername:String, rotation:Float, [pivotx = 0, pivoty = 0]);
Rotates a layer, in degrees. Default is 0 degrees.
-
layername
: The name of the layer to check. -
rotation
: Amount to rotate the layer to, in degrees. -
pivotx/pivoty
: Optional. Specify the pivot point to rotate around. Default is top left. Can useGfx.CENTER
,Gfx.TOP
,Gfx.BOTTOM
,Gfx.LEFT
andGfx.RIGHT
constants here.
import haxegon.*;
class Main{
function init(){
Layer.create("foreground");
Layer.attach("foreground");
//Set the rotation of the "foreground" layer to 45 degrees.
//Pivot around the centre.
Layer.rotate("foreground", 45, 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 LEFT and RIGHT to change the rotation of the "foreground" layer
var currentrotation:Float = Layer.getrotation("foreground");
if (Input.pressed(Key.LEFT)){
Layer.rotate("foreground", currentrotation - 2, Gfx.CENTER, Gfx.CENTER);
}else if (Input.pressed(Key.RIGHT)){
Layer.rotate("foreground", currentrotation + 2, Gfx.CENTER, Gfx.CENTER);
}
}
}