Draw a line between two objects like connect the dots

I am working to develop a drag and drop game. The user click and drags the object between the coutry name to the correct flag. A line is drawn on the screen connecting the two points.

I got the line to draw but I am struggling to position it correctly. I would appreciate any insights into what I am doing wrong. This is my first gdevelop project.

I am using the x,y positions in document-properties and those on the scene editor but these don’t give the results I expect. I am using point is in collision with FranceFlag draw from FranceText.X(), FranceText.Y() to FranceFlag.X(),FranceFlag.Y() with line. I have also tried using the exact x/y coordinates.

Not 100% sure, but I think the “Bouncing Ball and Rope” example on the examples page might help:

There’s a part on a Wishforge tutorial where he creates a rope swing. It may be useful for you to learn how to position the line correctly

dont know if someone still needs but:

make an image like an horizontal line, size 100 pixel width, 1 pixel height.
assign to an object.

make the origin and rotation point at the coord 0,5 x - 0,5 y.

get the distance between the two coords.

scale the line at the value “distance/100”

position the object at the first coord, and point to the second coord.


1 Like

@ErmesBertone, The easiest is to use a ShapePainter object. Going by the explanation given by the OP, it sounds like they were using this and needed to either uncheck the “Draw shape relative to the object position o the screen”, or place the ShapePainter at the origin.

Otherwise the ShapePainter object uses the position difference between it and the origin, and applies that as an offset to the line.


Yes, it is true that ShapePainter is the easiest way. Sometimes I forget I’m in 2021 and still think about using a C64.

Yeah, GDevelop makes it so much easier. I grew up with an Amstrad, programming Z80 assembler. and you appreciate the work that games engines, like GDevelop, do under the hood, leaving devs more time to focus on other game aspects (gameplay, gfx and vfx for example).

OMG, remembering times of assembly C64… just one accumulator for operations and
X Y to store data… LDA, BEQ, BEN…no thanks. :grinning:

Z80 Spectrum… CPC Amstrad and C64. What else.