How do I make a line to follow an object?

Hi guys! I have a lot of experience in programming, but I’m just learning GDevelop.

I am a teacher and I teach Electronics (I have a channel on YouTube too). I would like to build some small simulators to help my students.

The first “game” I want to make is an Transistor test with Multimeter.

I have a example for you to see what I mean: https://eletronicaeprogramacao.com/transistores/

Open the app in the link above and click in “NPN”. Then, you can see that when clicking in the red or the red probe, it moves. Look how the cable follows the probe.

I would like to do something similar in GDevelop.

I tried to use the “Shape Painter”, but with no success. See the video I made:

Any tips? Thanks!

1 Like

The shape painter seems to me a good solution. Have you created the pencil object for the shape painter?

Hi @Tarsio!
Pencil object? I have never heard about it and don’t find this in the GDevelop. I make a video to show what I have made so far:

The problem is the painter always disappears.

Thanks!

This is also something I don’t appreciate with it but the shape painter clears it’s “virtual canvas” before every frame automatically. What you have to do is store in a variable the positions where you want the line to be traced from an to, and on every frame (conditionless event) draw the line again.

Hi! I had imagined that I would have to do this, but I did not find an event that is called before each frame. Is there this event? Or is there another way to do this?

every event is executed before each frame, if you don’t add any further condition (like dragging).

You need to update the variable position when the object is dragged, and in another event WITHOUT ANY condition, drawing the line usinge the variable position.

PS. As “pencil object” I mean the shape painter object

1 Like

Ohh, an event without any condition! It worked! Thanks!

1 Like

If it helps you you can see the game loop like this: every frame as part of the game loop function, your event sheet is executed as a function. Every Event is converted to something like this (simplified)

if (condition1() && condition2 etc) {
    action1()
    action2()
    etc...
}

I am using this pseudocode as you say you have experience in programming. So a conditionless event is an if without argument called before each frame, aka it will be executed each frame.

1 Like