Get Every Line Connecting to Vertex, and Store It as an Array?

40 views
Skip to first unread message

Moshe Adriano Yosef Feit

unread,
Feb 12, 2016, 1:27:10 PM2/12/16
to haxef...@googlegroups.com

Hello everyone,


Suppose I draw a triangle object using FlxSpriteUtil.drawTriangle, how to get every line that connecting every 2 vertex (edges) of the triangle and store it in an array, any method? 
I've read the FlxSpriteUtil docs but didn't found any method to accomplish this.



Thanks,
Happy Valentine's day! :D

Moshe Adriano Yosef Feit

unread,
Feb 17, 2016, 6:23:59 AM2/17/16
to HaxeFlixel
Please, I really need help :(

Gama11

unread,
Feb 17, 2016, 6:44:34 AM2/17/16
to HaxeFlixel
What are you looking for as a result? An array of FlxPoints containing p1, p2 and p3?

FlxSpriteUtil isn't really intended for that, it just draws the triangle to a FlxSprite's BitmapData.

gratifist

unread,
Feb 17, 2016, 6:47:48 AM2/17/16
to HaxeFlixel
Depends what you want to do with the lines. If you want to edit them, I'm pretty sure you'll have to make each line individually and add them to an array.

Moshe Adriano Yosef Feit

unread,
Feb 17, 2016, 9:49:59 AM2/17/16
to haxef...@googlegroups.com
This is what I want to achieve.

The player is a shape, let's say a triangle. The player is able to rotate it, this triangle placed in the middle of the screen. There will be obstacles coming from the sill of the game window, moving to the center (to the player). This obstacle must hit the correct side within the triangle. For example:

Line(P1, P2) can only accept red obstacle
Line (P2, P3) can only accept blue,
Line (P3, P1) can only accept yellow.

If the obstacle fall into the wrong side of the triangle, the game is over. For example: Yellow collides with Line(P1,P2) which is only for red. Thus, in my logci, I need to make each side of the triangle as an independent object, and store it in an array. So I can do the collision checking.

# Check which side the obstacle is collided with

For i in LineArray:
if i is not for obstacle.color:
Game over
else:
score++:

I hope you get my points.

Gama11

unread,
Feb 17, 2016, 1:04:17 PM2/17/16
to haxef...@googlegroups.com
Let's take a look at the implementation of drawTriangle():

beginDraw(FillColor, lineStyle);
flashGfx.moveTo(X + Height / 2, Y);
flashGfx.lineTo(X + Height, Height + Y);
flashGfx.lineTo(X, Height + Y);
flashGfx.lineTo(X + Height / 2, Y);
endDraw(sprite, drawStyle);

So, to get the lines, you can use something like this:

function getTriangleLines(x:Float, y:Float, height:Float)
:Array<{ start:FlxPoint, end:FlxPoint }>
{
var p1 = FlxPoint.get(x + height / 2, y);
var p2 = FlxPoint.get(x + height, y + height);
var p3 = FlxPoint.get(x, height + y);
return [
{ start: p1, end: p2 },
{ start: p2, end: p3 },
{ start: p3, end: p1 }
];
}

Moshe Adriano Yosef Feit

unread,
Feb 18, 2016, 7:31:51 AM2/18/16
to HaxeFlixel
So, that means, I have to draw the triangle using the manual way, point by point and draw the lines, instead of FlxSpriteUtil.drawTriangle?
In this case, when player rotate, it must be something like clear screen have to be done first, then re-draw the triangle, right?

If the control is freedom - rotate by 1 degree while player hold down the button/screen, wouldnt it be a memory killer?

Gama11

unread,
Feb 18, 2016, 7:34:37 AM2/18/16
to HaxeFlixel
You can still use drawTriangle for drawing, but you need a helper method to figure out the line start and end points. Figuring out the location of those points after rotation could be a bit trickier however.
Reply all
Reply to author
Forward
0 new messages