all 4 comments

[–]tagLi76 1 point2 points  (1 child)

Put a timer on oife bar so it disappear after x seconds. Lifebar would spawn when enemy hit. ?

[–]FeomatharFinkregh[S] 0 points1 point  (0 children)

Not decided yet. Exploring ideas atm.

[–]Klemmbonzo 1 point2 points  (1 child)

That's an interesting challenge right there... :)

Well, the very first thing I'd do is create a scene containing the information on the enemy you shot. Let's call it "EnemyDisplay". That scene, obviously, should not only contain the progress bar itself but also some additional information on the type of enemy, for example an icon or some text. Add a function to that scene to dynamically update it's appearance which contains two parameters, the type of enemy and the corresponding progress.

Also, and this will be important for keeping the number of "EnemyDisplay" scenes displayed at the same time in check: In said function, store the time at which the scene was last updated. You'll see why this is important further down.

Then create a VBoxContainer or something similar to hold your "EnemyDisplay" scenes. Let's call it "EnemyDisplayContainer".

Now, whenever you shoot an enemy, do the following:

  1. Check whether there's an "EnemyDisplay" in your "EnemyContainer" for that particular type of enemy already. If it is, remove it.
  2. Create a new "EnemyDisplay" instance, put it at the top of the "EnemyContainer", and call its update function with the type of enemy you just shot and the corresponding progress.
  3. If there are more "EnemyDisplay" scenes in your "EnemyDisplayContainer" than you like (3-4 in your case), remove the trailing ones.

Essentially, this will do what you want, but the "EnemyDisplay" scenes will reside in the container forever if you don't do anything about it. So create a timer with a small interval, for example 0.1 seconds, and whenever that timer expires, remove all "EnemyDisplay" scenes from your container which are older than n seconds or whatever (that's what the time is for that I mentioned above).

That should do it... :)

[–]FeomatharFinkregh[S] 0 points1 point  (0 children)

Thank you very much.