Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ;
- import flixel.FlxCamera;
- import flixel.FlxSprite;
- import flixel.group.FlxGroup;
- import flixel.util.FlxPoint;
- import flixel.FlxBasic;
- import flixel.FlxG;
- import flixel.FlxSprite;
- import flixel.FlxState;
- import flixel.util.FlxMath;
- /**
- * ...
- * @author ...
- */
- class SelectionBox extends FlxSprite
- {
- /**
- * Adding to playstate example:
- *
- *
- * override public function create():Void
- {
- super.create();
- var _sel:SelectionBox = new SelectionBox();
- //_sel.available = true; //set true by default.
- add(_sel);
- }
- *
- */
- public var selected:FlxGroup;
- public var selectionColor:Int = 0x88800000; //Can be whatever at whatever transparency.
- public var startPos:FlxPoint = new FlxPoint(0,0);
- public var endPos:FlxPoint = new FlxPoint(0,0);
- public var target:FlxBasic;
- public var keepSelection:Bool;
- public var available:Bool = true;
- public var Object:Bool;
- public function new()
- {
- super();
- makeGraphic(1, 1, 0x00000000);
- width = height = 1;
- x = y = -1;
- scrollFactor.x = scrollFactor.y = 0;
- }
- override public function update():Void
- {
- if (available) drawSquare();
- scrollFactor.x = scrollFactor.y = 0;
- super.update();
- }
- public function drawSquare():Void
- {
- if (FlxG.mouse.justPressed)
- {
- startPos.x = FlxG.mouse.screenX;
- startPos.y = FlxG.mouse.screenY;
- x = startPos.x;
- y = startPos.y;
- }
- if (FlxG.mouse.pressed)
- {
- endPos.x = FlxG.mouse.screenX;
- endPos.y = FlxG.mouse.screenY;
- width = Math.abs(startPos.x - endPos.x);
- height = Math.abs(startPos.y - endPos.y);
- //if (width > 0 && height > 0) makeGraphic(Std.int(width), Std.int(height), selectionColor);
- if (width > 0 && height > 0 ) makeGraphic(Std.int(width), Std.int(height), selectionColor);
- if (endPos.x < startPos.x) x = endPos.x;
- if (endPos.y < startPos.y) y = endPos.y;
- }
- if (FlxG.mouse.justReleased)
- {
- if (FlxMath.getDistance(startPos,endPos) <= 1)
- {
- makeGraphic(1,1);
- x = y = -1;
- }
- else
- {
- makeGraphic(1,1);
- x = y = -1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement