Create name label that moves with the object

Hey guys!

In my project I want the player to choose between viewing the name label of the objects or not. My problem is with my moving objects, I have 4 lysosomes and I want their name label to show when the player presses ViewButton and each should have their name label and should move along with them. I have no Idea how to do that, can someone help me?

Here’s how I coded it:

Sorry, it’s super messy.

Did you 1st link your objects?

2 Likes

I did, but I think I did the logic wrong. Thank you for this!

1 Like

When you link objects, you need to have only 1 of each instance picked at a time.You can add the text when the main object is created or use something like a for each object. or other condition to choose 1 object at a time. Otherwise, GD will use the oldest created instance of that object.

This last event

The object names in the link condition are reversed. If you go through the character then you need to pick the text object linked to the character.

For each character
Pick Name linked to character

For each name
Pick character linked to name

I did this and it worked! Thank you!

I do have one more question, why does my preview lag when I add this (Vacuole):

I’m quite sad because I was planning to make like 7 of these for my other objects but my preview just won’t even move.

1 Like

I have no idea cause events alone can’t tell what else is running in your game

BUT 1 thing i notice


In both cases you are 1st taking into acc
THEN checking view button

This is stupid
Gdevelop reads stuff from top to bottom

So 1st you check variable then you take into acc

Cause as i assume view button is one object
Where you pick many objects here

THEN it would make sense to 1st filter it by if view button var =1

And then pick objects to filter ones that are linked and are not

For efficiency, you could split the logic up. Add and link the name object as a subevent of the button is released and then move the name object as a subevent that checks the variable. There’s no need to check the variable within the for each object. The value isn’t going to change and it’s using processing time for each instance instead of just once.

Button is released
Subevents
… For each object
… …add name and link events

Variable View of ViewButton =1
Subevents
… For each object
… … Move name events

Thank you for this!!!

1 Like