I'm having an issue with my healthbar

Get help using Construct 2

Post » Sun Nov 04, 2012 2:56 am

I'm using the healthbar system from Zelda here:
http://www.scirra.com/arcade/example/320/zelda-style-lifebar

Here is my .capx:
http://dl.dropbox.com/u/91745263/WorkingTitle.capx

If you compare the event parts between the two, they are correct.
It is by far the most bizarre situation I have ever been in.

I spent 6 hours trying to find what the issue is.
So, if anyone of you masters out there find out the problem, please please tell me what's wrong.

Here is what is known so far:
The math seems to be working.
The coins in the game can only be collected if you have less than full health.
If you have full health, you cannot collect the coins.
So, if you "flash"/get hurt two times, you can collect 2 coins, but can't collect a 3.
So, the math seems to be right, it's just not changing the animation frame.

I really appreciate it!

PS: Switch to Level1 layout before running it
PS: The fish and biohazard enemies will decrease life
B
3
Posts: 9
Reputation: 643

Post » Sun Nov 04, 2012 4:37 am

Hmm, not sure why it doesn't work, looks pretty much the same to me.

I would make sure that the first loop only runs once at the beginning of the layout. Seems to work fine if you add in an "On start of layout".

I changed some other things as well, and deleted a bunch of stuff to make it smaller, but the events should be clear enough:

EvanMCHealthBar.capx (r108.2)Nimtrix2012-11-04 04:38:48
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Sun Nov 04, 2012 6:14 pm

When you destroy a sprite it doesn't get destroyed until the next top-level event. So the 'HealthBar' sprites destroyed in event 13 aren't really destroyed until event 20.
What happens is:
Event 13 flags the 5 HealthBar sprites to be destroyed and creates another 5 HealthBar sprites on top of them.
Event 14 sets the animation frames correctly for the first 5 sprites which are going to be destroyed.
At event 20 the 5 sprites are destroyed, leaving the 5 new sprites which haven't had their animation frames set.


(Also in event 15 it should be playerLife/2 in the first condition)

@Nimtrix Creating the health sprites on start of layout wouldn't let you dynamically change the maxLife like in the arcade example. But if he doesn't need to do that then it would probably be better. Destroying and recreating the sprites every tick doesn't seem like a great idea.ramones2012-11-04 18:20:27
B
54
S
28
G
18
Posts: 1,520
Reputation: 24,990

Post » Sun Nov 04, 2012 6:38 pm

@ramones: Yeah, I suppose you're right. But you could just recreate the HealthBar objects every time you change maxLife, wouldn't be too difficult to handle imo.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, shinkan, stylie1, tarek2 and 12 guests