FlxShapeArrow overconstrained?
-
I was looking at
FlxShapeArrow
, and its constructor is/** * Creates a line with an arrowhead on the end point * * @param X X location of the sprite canvas * @param Y Y location of the sprite canvas * @param Start starting point of the arrow * @param End ending point of the arrow (this is where the arrowhead is) * @param ArrowSize how big the arrow is (height) * @param LineStyle_ line style for the line and arrowhead * @param OutlineStyle_ line style for the outer line (optional) */ public function new(X:Float, Y:Float, Start:FlxPoint, End:FlxPoint, ArrowSize:Float, LineStyle_:LineStyle, ?OutlineStyle_:LineStyle)
It seems to me that the
X
andY
parameters are just there to keep consistency withFlxSprite
, and aren't really useful. TheStart
andEnd
parameters are given as offsets fromX
andY
, and the width/height of the sprite is worked out based on the difference betweenStart
andEnd
. This means that if the upper-left-most point is not at0, 0
, part of the arrow won't get drawn.I was working on a prototype where I wanted to be able to drag the ends of arrows around, and the simplest way to do this seemed to be to wrap this class with another, that handles this adjustment automatically, i.e.
class Connection extends FlxShapeArrow { public function new(Start:FlxPoint, End:FlxPoint, ArrowSize:Float, LineStyle_:LineStyle, ?OutlineStyle_:LineStyle) { super(0, 0, Start, End, ArrowSize, LineStyle_, OutlineStyle_); correctCoordinates(); } public function setPoint(x:Float, y:Float) { x -= this.x; y -= this.y; point.set(x, y); correctCoordinates(); } public function setPoint2(x:Float, y:Float) { x -= this.x; y -= this.y; point2.set(x, y); correctCoordinates(); } private function correctCoordinates() { var minX:Float = Math.min(point.x, point2.x); x += minX; point.x -= minX; point2.x -= minX; var minY:Float = Math.min(point.y, point2.y); y += minY; point.y -= minY; point2.y -= minY; } }
Is there any reason why the base version of the class doesn't work this way?
-
Hey Harold,
Yes, you are correct, the X and Y params are used for FlxSprite since FlxShapeArrow extends FlxShape which extends FlxSprite.
If I'm being completely honest my knowledge of the shapes in Flixel is a little rusty. Out of curiosity are you planning to move from shapes into your own custom sprites?
If you're able to check out the HaxeFlixel channel in the Haxe Discord server I feel like someone over there would be able to help out https://discord.gg/aZus3R
-
My prototype ended up moving away from using
FlxShapeArrow
, so it's not a serious concern. This was just my first foray into HaxeFlixel, and the design here didn't really make sense to me. Usually when that happens with a new technology, there's something fundamental I haven't properly understood. If this code looks good, though, then there's no problem :)
-
Fair enough, IMO I tend to draw simple sprites and use that instead of using the shapes provided by flixel (unless it's a simple box, FlxSprite is good for that).
But yeah welcome to the world of HaxwFlixel, if you have any more questions feel free to as them in the forum, or discord channel. The community here is small but really friendly.
-
You will realize that a dream is not difficult to fulfill if you get out of your comfortable bed and take action to make it come truecookie clicker . Wishing you a successful day!