Line drawing question

Get help using Construct 2

Post » Tue Jul 15, 2014 4:13 pm

Hi all,

I've just started using Construct and ran into a problem I can't solve.

I have a project with two types of sprites, circles and lines. I'd like to connect circles with lines in a random fashion: on creation every circle spawns a line that is connected to another random circle.
The circles would be moving around, so I need to redraw all the lines on every tick. To do this, I have the following variables in the circle:

start: the index of the circle from which the line comes
end: the index of the circle where the line is going
startX, startY, endX, endY: the XY positions of the start point and end point, respectively.

Here's how the redraw procedure looks like now:

Image

You can see that for each Line I query the start and end positions, put them in the variables, and use them to define the line.
If I use something like Circle(n).X , Circle(n).Y for positions, when some circles are destroyed, the lines redraw to different instances of circles, because the ID changes. That's why I'd like to select the circles by a custom ID.
For me it would be logical to query the positions of the circles whose (custom variable) indexes equal the Line's "start" and "end" variables. But how can I pick like that, when I need to have info from two different circle instances in the same expression (distance)?

The current setup is working correctly by the way, but it's really slow because of the "for each" cycle. Is there a way to do this without the for loop or the startX,startY,endX,endY variables?

Thanks a lot!

Edit:
Okay, I've already discovered that this works without the every tick condition too, but it's still really slow, that's why I'd like to know a better way for this.
B
3
Posts: 1
Reputation: 177

Return to How do I....?

Who is online

Users browsing this forum: Solomon and 8 guests