Hey there, I have problems making a HP bar fade out for each enemy separately. I’m using an opacity tween for the bars, but it doesn’t work as intended.
What is the actual result
When I deal damage to the first enemy, it works great, afterwards I damage the second, this time it works as well, BUT when I go back to the first enemy, the HP bar flashes or doesn’t even appear on screen.
Afterwards, if I hit the enemy again it works properly. And this process repeats.
Related screenshots
I’m hoping someone can have a look at it, I know it’s quite messy but I’m still a beginner.
The second screenshot is where the main problem is, first one is for context.
Don’t use the Repeat for each object with conditions so much. Instead, have an event with the conditions, and an unconditional Repeat for each object as a subevent off that. This will reduce the number of objects iterated over (see my mockup at the end of this post).
By default, all conditions need to be true before the event’s actions are run. So no need for that If all of there conditions are true condition
That trigger once in the first Repeat for each instance of Enemy1 doesn’t work how you think. It works on an object level, not on an object instance level. So if one of the Enemy1 objects meets the criteria, then any other Enemy1 objects that also meet the criteria are ignored because they are of the same object type.
Now to your problem. In the first screen shot, beginning of scene actions will only work if there is 1 Enemy1 on the scene. If you think about it, if there are more than 1 Enemy1 on the scene at the start, which instance will GDevelop use and link to? This is a case where you will need to use a Repeat for each object as a subevent off the Beginning of scene event.
Thank you for pointing things out, I still have much to learn, I started tinkering with GDevelop around a week ago.
I revised my code as you suggested, but my main problem still persists. I feel like it has to do with my object timer, but I have no clue exactly what causes it.
The HP bars still flash or don’t appear when I switch enemies, after I hit again they work again.
What works so far:
I hit an enemy, only his HP bar is on screen
The HIT timer resets well, so while I’m damaging an enemy the HP bar doesn’t fade out
Switching to another enemy doesn’t reset the previous enemy’s HP bar, so that fades out
BUT then again, switching to the first enemy that I damaged the HP bar just flashes or doesn’t appear forthat hit. If I hit it again, the HP bar appears.
In the 3rd event (with the condition Health has just been damaged on Enemy1) you’ll need to add a Repeat for each instance of Enemy1 as a subevent with the FlatHeartBar link to Enemy1 condition.
Why don’t you put the timer on the FlatHeartBar, instead of the Enemy1 object? After all, the timer is just for the FlatHeartBar opacity, and not anything for the Enemy1 object, Then you wouldn’t have to worry about checking the link between the two (which will need a Repeat for all instances of Enemy1). Just check for FlatHeartBar with a timer >= 2 seconds, and fade the bar.
Of which, by only resetting the timer in the 4th event the timer will start again, and every 2 seconds the fade opacity will kick off. This repeated over and over. It is quite likely that this could be that interfering with the showing of the FlatHeartBar, causing it to flicker.
I highly appreciate your time and effort for helping me out, I think it works now! I put the obj timer on the FlatHeartBar, integrated a pause/unpause timer expression and reorganized the events as you recommended (Repeat for all instances → as a subevent). There was a remaining flickering when I hit the enemy while it was in the fadeout phase, but I solved it with a remove tween expression.
It ain’t that simple for a rookie like me.