"Animated" health bar

Not favoritedFavorited Favorited 0 favourites
  • 7 posts
From the Asset Store
Health, Weapon & Rage Bars for your Games. Easy to use & Customize.
  • I would like to have a health bar "animation" effect. But because the health bar design is somewhat complicated (basically it has an exterior design), my initial idea to relate the health bar to a variable hp was to have two sprites, one was 100hp and one was 0hp. I then overlay those in the layout view (100hp in front of the 0hp), but now I want to try and make it so that the code will crop the full hp bar, revealing the 0hp bar underneath slowly as you lose health. Is there a better way to do this? If not, how do I make this cropping idea work? I couldn't find a way to do so.

    Tagged:

  • Here are two options.

    I often use the “tween” behavior to change the size of the health bar.

    fex.net/s/a4tnnzy

  • Ah I see, how would I make this work in typescript? I can't figure out how to do `lerp`

  • The option using `lerp` linear interpolation is not very good, as it requires performing this action every tick even if the health parameters have not changed. If you don't know how to do this in TS, you can simply subtract half a pixel from the length until it becomes necessary; this is not visible to the naked eye.

    But it would be better to use “tween” only when necessary during health loss.

  • the way I did it was just to have an instance variable called "health" that was tied to the player sprite, set the origin point of the health bar all they way left, set width to the instance variable, and made it so that when the player got hit or smth, the instance variable went down.

    P.S. no clue if you'll use this, but I still hope it helps!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The option using `lerp` linear interpolation is not very good, as it requires performing this action every tick even if the health parameters have not changed. If you don't know how to do this in TS, you can simply subtract half a pixel from the length until it becomes necessary; this is not visible to the naked eye.

    But it would be better to use “tween” only when necessary during health loss.

    I got it working with your lerp idea! It seems really cool. When you say not very good do you mean performance wise?

  • I got it working with your lerp idea! It seems really cool. When you say not very good do you mean performance wise?

    These are minor details, and Construct3 can handle them well. As an artist, you are free to do this and even more.

    In terms of performance, it won't be immediately noticeable, because if there are 10 or 100 such health bars on the stage, it won't change much, but if there are more than a thousand of them, it could potentially harm the project.

    I am more concerned about the logic of this, because every time our game will need to go through each health bar even when it has not changed.

    Wouldn't it be better to change the amount of health when receiving damage from the enemy and start a “tween” to decrease it? Or only increase health when we drink potions.

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