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

Get help using Construct 2

Post » Wed Mar 12, 2014 7:25 pm

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.

Image

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

Spawn FriendlyBase on layer 0 (image point 0)
B
5
S
1
Posts: 34
Reputation: 364

Post » Wed Mar 12, 2014 7:45 pm

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.
B
7
S
1
G
1
Posts: 56
Reputation: 732

Post » Thu Mar 13, 2014 10:12 am

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

Image

I thought this would execute when I spawn a new tank?
B
5
S
1
Posts: 34
Reputation: 364

Post » Thu Mar 13, 2014 10:52 am

Do a "new tank" function, and have it do all that from the function maybe? Also read up on containers if that will help.
B
27
S
7
G
6
Posts: 268
Reputation: 3,852

Post » Thu Mar 13, 2014 10:57 am

Set the healtbar's angle to the angle of the tank you're creating.
B
14
S
3
G
1
Posts: 255
Reputation: 2,027

Post » Thu Mar 13, 2014 12:11 pm

@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.

@Rabenmutter 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....
B
5
S
1
Posts: 34
Reputation: 364

Post » Thu Mar 13, 2014 1:22 pm

Set the angle right before you pin the object. (Actions-> Healthbar -> SetAngle).
B
14
S
3
G
1
Posts: 255
Reputation: 2,027

Post » Thu Mar 13, 2014 3:56 pm

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
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Post » Thu Mar 13, 2014 4:05 pm

caiorosisca wrote: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
I will not let you reach the sisters
Nature Forums
B
11
S
5
G
2
Posts: 496
Reputation: 2,306

Post » Fri Mar 14, 2014 1:30 pm

@caiorosisca @Rabenmutter 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 @Rabenmutter suggested)

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

Thanks again for your help.
B
5
S
1
Posts: 34
Reputation: 364


Return to How do I....?

Who is online

Users browsing this forum: JayH and 9 guests