package;
import flixel.FlxG;
import flixel.FlxState;
import flixel.ui.FlxButton;
import flixel.util.FlxColor;
class PlayState extends FlxState
{
override public function create():Void
{
super.create();
FlxG.debugger.drawDebug = true;
// Just scale -> scale from center :) , wrong hitBox :(
var button1:FlxButton = new FlxButton(200, 200, "1");
button1.makeGraphic(16, 16, FlxColor.BEIGE);
button1.scale.x = button1.scale.y = 10;
button1.onOver.callback = onOver.bind(button1);
button1.onOut.callback = onOut.bind(button1);
add(button1);
// Scale with updateHitbox -> scale from top left :( , good hitBox :)
var button2:FlxButton = new FlxButton(400, 200, "2");
button2.makeGraphic(16, 16, FlxColor.BEIGE);
button2.scale.x = button2.scale.y = 10;
button2.updateHitbox();
button2.onOver.callback = onOver.bind(button2);
button2.onOut.callback = onOut.bind(button2);
add(button2);
}
private function onOver(btn:FlxButton):Void { btn.color = FlxColor.LIME; }
private function onOut(btn:FlxButton):Void { btn.color = FlxColor.WHITE; }
}
button.scale.x = button.scale.y = scale;
button.width = button.scale.x * button.frameWidth;
button.height = button.scale.y * button.frameHeight;
button.centerOffsets(true);
button3.width = button3.scale.x * button3.frameWidth;
button3.height = button3.scale.y * button3.frameHeight;
button3.centerOffsets();
button3.x -= (button3.width - btn3LastWidth) / 2;
button3.y -= (button3.height - btn3LastHeight) / 2;
btn3LastWidth = button3.width;
btn3LastHeight = button3.height;
package;
import flixel.FlxG;
import flixel.FlxState;
import flixel.ui.FlxButton;
import flixel.util.FlxColor;
import flixel.tweens.FlxTween;
class PlayState extends FlxState
{
private var button1:FlxButton;
private var button2:FlxButton;
private var button3:FlxButton;
private var scale:Int = 4;
override public function create():Void
{
super.create();
FlxG.debugger.drawDebug = true;
for (x in 1...4) {
for (y in 1...3) {
var button:FlxButton = new FlxButton(x * 160, y * 140, Std.string(10 * y + x));
button.makeGraphic(16, 16, FlxColor.BEIGE);
button.onOver.callback = onOver.bind(button);
button.onOut.callback = onOut.bind(button);
add(button);
switch (10 * y + x) {
case 11:
button.scale.x = button.scale.y = scale;
case 12:
button.scale.x = button.scale.y = scale;
button.updateHitbox();
case 13:
button.scale.x = button.scale.y = scale;
button.width = button.scale.x * button.frameWidth;
button.height = button.scale.y * button.frameHeight;
button.centerOffsets(true);
case 21:
button1 = button;
FlxTween.tween(button1.scale, { "x":scale, "y":scale }, 2);
case 22:
button2 = button;
FlxTween.tween(button2.scale, { "x":scale, "y":scale }, 2);
case 23:
button3 = button;
FlxTween.tween(button3.scale, { "x":scale, "y":scale }, 2);
}
}
}
}
override public function update():Void
{
super.update();
button2.updateHitbox();
var btn3LastWidth = button3.width; var btn3LastHeight = button3.height;
button3.width = button3.scale.x * button3.frameWidth;
button3.height = button3.scale.y * button3.frameHeight;
button3.centerOffsets();
button3.x -= (button3.width - btn3LastWidth) / 2;
button3.y -= (button3.height - btn3LastHeight) / 2;
btn3LastWidth = button3.width;
btn3LastHeight = button3.height;
}
private function onOver(btn:FlxButton):Void { btn.color = FlxColor.LIME; }
private function onOut(btn:FlxButton):Void { btn.color = FlxColor.WHITE; }
}
override public function update():Void
{
super.update();
var lastWidth:Float = button.width;
var lastHeight:Float = button.height;
button.updateHitbox();
button.x -= (button.width - lastWidth) / 2;
button.y -= (button.height - lastHeight) / 2;
}