-
Notifications
You must be signed in to change notification settings - Fork 0
Layer.scaley
Terry Cavanagh edited this page Feb 28, 2018
·
1 revision
Layer.scaley(layername:String, scale:Float, [pivotx = 0, pivoty = 0]);
Scales a layer vertically only. Default is 1. To scale horizontally, try Layer.scalex, or Layer.scalexy.
-
layername
: The name of the layer to check. -
scale
: Amount to scale the layer. 1.0 is normal size. -
pivotx/pivoty
: Optional. Specify the pivot point to scale 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 scale of the "foreground" layer to half horizontal, double vertical.
//Pivot around the centre.
Layer.scalexy("foreground", 0.5, 2.0, 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 ARROW KEYS to change the scale of the "foreground" layer
var horizontalscale:Float = Layer.getscalex("foreground");
var verticalscale:Float = Layer.getscaley("foreground");
if (Input.pressed(Key.LEFT)){
Layer.scalex("foreground", horizontalscale * 0.9, Gfx.CENTER, Gfx.CENTER);
}else if (Input.pressed(Key.RIGHT)){
Layer.scalex("foreground", horizontalscale * 1.1, Gfx.CENTER, Gfx.CENTER);
}
if (Input.pressed(Key.DOWN)){
Layer.scaley("foreground", verticalscale * 0.9, Gfx.CENTER, Gfx.CENTER);
}else if (Input.pressed(Key.UP)){
Layer.scaley("foreground", verticalscale * 1.1, Gfx.CENTER, Gfx.CENTER);
}
}
}