Attaching Objects to Other Objects

This forum is currently in read-only mode.
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • This is a tricky problem I've been thinking about for a feature that I'm working on. Basically, I'd like to have one type of object following another type of object, so that it always stays at the same position as the object it's following.

    What makes this more difficult is that I have more than one object of the same type. Let's say I have a type of objects called "Monster" and another type called "Health Bar". I want every monster to have a health bar, and it should be displayed above the monster's head at all times. But how can I make a unique health bar for each monster, and then make sure they're all at the right position?

    Ideally, this should be done in an efficient manner so that the position of health bars will only be set when it must be set. I don't want a loop that runs every tick and sets the position of every health bar on the level. I would like to only move health bars for the monsters that have moved that tick; stationary monsters don't need to move their health bar.

    Any help with this would be appreciated.

  • I always adde the parent unique.id to a variable in the child object then pick by comparing (child variable and parent unique id).

    <img src="smileys/smiley2.gif" border="0" align="middle" />

  • Put "Monster" and "Health Bar" in a container. Then the positioning can be done with one event:

    + System: Always (every tick)

    -> healthBar: Set position to Monster.X, Monster.Top-16

    -> healthBar: Set width to Monster ('health')

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Construct has a hidden feature that automatically does a lot of this.

    To use it:

    Put everything that acquires a health bar into a family.

    Set the healthbar to destroy at startup.

    Then, at the start of layout, for each member of that family, create a health bar.

    Then in another event, set the position of the health bar to family.x, family.top-howevermuch.

    Construct will automatically place a healthbar at each family member. You can also use this technique to set the width of the healthbar to family variables, such as family('hp'), and construct will automatically know which instance to use.

    This is actually better than the container method, as it is simpler to set up, all automatic and doesn't require a different health bar object for each sprite.

  • I believe I know what you are trying to do :]

    yourfilelink.com/get.php

    Edit: Sry Arima, were Irl buddies. ;]

  • Very simple method.

  • Please stick to english on the forums, or at least provide a translation. Thanks!

  • Thanks for the help everyone! I'm going to try this soon and I'll let you know if I run into any more problems with it.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)