Position a sprite relatively to an object + object inside an object

Hi,

I have an object which has a sprite and there is a another sprite above it (an hpbar), I want to resize it so that the red hp bar decreases. However, doing so, my hpbar is centered and hence decreasing in both sides. What I would like is that it only decreases on the right side. Am I clear ?

Is there a way to do it ?

My idea to work around this is to both rescale the image and update the position to the sprite however I cannot find how to change the position of a sprite.

I’ve seen on the forum that we don’t set the position of the sprite but only of the object (which is unnatural because I can set the position in defold’s editor), so I wanted to create an object inside my object which contains the hpbar but I cannot do that either.

By the way I have another similar problem and I will create another thread if need be. I have a file level_1.collection and I have a player object which has a camera object inside it which has a camera inside it. I would like to use an object file for my player instead, but again, I cannot create objets in objets files, is there a way to do it ?

Use collections.

Single game object files are OK when it’s something really simple that only needs one game object, but for most things you want to use a collection so you can add multiple game objects as necessary (like in your situation).

You can check out this related thread: Game Object Or Collections - Best Practices
…or this one: Is this ok to use collection instead of game objects?

The only drawback with collections is when you spawn them it’s a little more work to set properties on their objects, but for static stuff it makes no difference.

2 Likes