when i spawn a new sprite parts don't look right

  • Hello,

    I've added individual health bars to my units on the RTS template. This is working great, however when I spawn a new unit the health bar is't positioned correctly.

    Can someone suggest an approach to do this correctly, currently I am just;

    Spawn FriendlyBase on layer 0 (image point 0)

  • Maybe you need to add the Pin behavior:

    https://www.scirra.com/manual/99/pin

    Perhaps you would create your sprite, then pin the health bar to it at a certain offset/location. Then, when you spawn a new unit, it will include the pinned health bar.

  • I already do this as part of the "On create" event for the tank bases that exist initially when the game loads;

    I thought this would execute when I spawn a new tank?

  • Do a "new tank" function, and have it do all that from the function maybe? Also read up on containers if that will help.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Set the healtbar's angle to the angle of the tank you're creating.

  • roracle i'll give it a go, i'm using a container now, but perhaps there is more 'batteries included' with C2 containers that i'm unaware of.

    how do I set the angle and position? The health bar is in a container with the tank and is also pinned to the tank, so when I "Spawn FriendlyBase on layer 0 (image point 0)" it all just appears....

  • Set the angle right before you pin the object. (Actions-> Healthbar -> SetAngle).

  • Not sure what look you are trying to achieve, but maybe not even pin the angle at all. Pin the healthbar to position only and it will always be on top of each tank

  • Not sure what look you are trying to achieve, but maybe not even pin the angle at all. Pin the healthbar to position only and it will always be on top of each tank

    That seems right

  • caiorosisca Thanks for your suggestions, both lead me to the answer.

    To fix this;

    • I added another image point to the tank base On the 'On Created' event for the tank base I
    • Set the position of the healthbar components to new image point of the tank base
    • Kept the pin as Position & angle as that locked it to my bases angle and position
    • Added an action to set each healthbar component (sprite) to the same angle at the tank base (as suggested by

      suggested)

    I also had to play with the order of components, but it works great now.

    Thanks again for your help.

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