Advertisement
Guest User

Untitled

a guest
Jul 5th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. package ;
  2.  
  3. import flixel.FlxCamera;
  4. import flixel.FlxSprite;
  5.  
  6. import flixel.group.FlxGroup;
  7. import flixel.util.FlxPoint;
  8. import flixel.FlxBasic;
  9.  
  10. import flixel.FlxG;
  11. import flixel.FlxSprite;
  12. import flixel.FlxState;
  13. import flixel.util.FlxMath;
  14.  
  15. /**
  16. * ...
  17. * @author ...
  18. */
  19. class SelectionBox extends FlxSprite
  20. {
  21.  
  22. /**
  23. * Adding to playstate example:
  24. *
  25. *
  26. * override public function create():Void
  27. {
  28.  
  29. super.create();
  30.  
  31. var _sel:SelectionBox = new SelectionBox();
  32. //_sel.available = true; //set true by default.
  33. add(_sel);
  34.  
  35. }
  36. *
  37. */
  38.  
  39.  
  40. public var selected:FlxGroup;
  41. public var selectionColor:Int = 0x88800000; //Can be whatever at whatever transparency.
  42.  
  43. public var startPos:FlxPoint = new FlxPoint(0,0);
  44. public var endPos:FlxPoint = new FlxPoint(0,0);
  45. public var target:FlxBasic;
  46. public var keepSelection:Bool;
  47. public var available:Bool = true;
  48.  
  49. public var Object:Bool;
  50.  
  51. public function new()
  52. {
  53. super();
  54.  
  55. makeGraphic(1, 1, 0x00000000);
  56. width = height = 1;
  57.  
  58. x = y = -1;
  59.  
  60. scrollFactor.x = scrollFactor.y = 0;
  61.  
  62.  
  63. }
  64.  
  65. override public function update():Void
  66. {
  67. if (available) drawSquare();
  68.  
  69.  
  70. scrollFactor.x = scrollFactor.y = 0;
  71. super.update();
  72. }
  73.  
  74. public function drawSquare():Void
  75. {
  76. if (FlxG.mouse.justPressed)
  77. {
  78. startPos.x = FlxG.mouse.screenX;
  79. startPos.y = FlxG.mouse.screenY;
  80.  
  81. x = startPos.x;
  82. y = startPos.y;
  83.  
  84. }
  85.  
  86. if (FlxG.mouse.pressed)
  87. {
  88.  
  89. endPos.x = FlxG.mouse.screenX;
  90. endPos.y = FlxG.mouse.screenY;
  91.  
  92. width = Math.abs(startPos.x - endPos.x);
  93. height = Math.abs(startPos.y - endPos.y);
  94.  
  95. //if (width > 0 && height > 0) makeGraphic(Std.int(width), Std.int(height), selectionColor);
  96. if (width > 0 && height > 0 ) makeGraphic(Std.int(width), Std.int(height), selectionColor);
  97.  
  98. if (endPos.x < startPos.x) x = endPos.x;
  99. if (endPos.y < startPos.y) y = endPos.y;
  100.  
  101.  
  102. }
  103.  
  104. if (FlxG.mouse.justReleased)
  105. {
  106. if (FlxMath.getDistance(startPos,endPos) <= 1)
  107. {
  108.  
  109. makeGraphic(1,1);
  110. x = y = -1;
  111. }
  112. else
  113. {
  114. makeGraphic(1,1);
  115. x = y = -1;
  116. }
  117.  
  118.  
  119.  
  120. }
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement