Picking Instance Problems

0 favourites
  • 8 posts
From the Asset Store
For problem solving, puzzles, bubbles, platforms and other adventures.
  • Hello guys,

    I'm having some trouble with the Player Health HUD.

    The concept is this:

    The Player's Hit Points are represented by Hearts. Each Heart is a different Sprite.

    The Player can purchase Items that increase his Max Health to a maximum of 8.

    He starts with 3 though.

    Every time he gets hit, the Heart that is furthest from the point 0 in x gets dark (Animation change.)

    I managed to accomplish this and it works great when the Player gets damaged by 1.

    If damaged by more than one though, the system falls apart and only shows one damaged heart from then on.

    I've tried doing it by my own functions and Dictionary and by using the Health behavior bought from the Scirra Store with no luck.

    Here is what I'm doing:

    [Creating the Heart Sprites]

    On start of layout

    Repeat.Player.PlayerMaxHealth Times -> Create object HUD_Heart on layer "HUD" at (40 + (loopindex * 14), 24)

    [Damage]

    Player - On Health Damaged

    HUD_Hearts - Pick furthest to (0,24)

    HUD_Hearts - Is animation "Default" playing

    Repeat Player.Health.LastDamagePoints times (Health behavior includes value for the last damage received)

    ->

    Set animation to "Dark"

    (Wait 0.5)

    So, do you have any ideas? As I've said it works fine until the character gets damaged for more than 1 HP.

    I've tried various variations on the above logic yet nothing changed.

    I'm quite new to Construct though so maybe I'm missing something?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hello leoncross,

    I suggest to use only one sprite with different frames and animations for the HP bar.

    Thats much easier. You can take a look at my example (open in C3 - https://editor.construct.net/)

    https://1drv.ms/u/s!Ap_-qxoGKbDcgzxrYGolqjt1E4DJ

  • Yeah, i did a similar thing, using a tiled background to create a bar of hearts (basically tiling a single heart)

    Depending on the amount of health the texture would grow wider and hence repeat multiple hearts.

    For empty hearts you'd simply have a another black heart texture beneath the red hearts.

    The black texure would reflect the amount of the health max, the red texture that of the current health.

    With the animation approach you'd probably need many variations to cover all the possible numbers full and empty of hearts?

  • Hey facecrime,

    the frames and animations are done real quick.

    It would be a bit more elaborate if, like in Zelda, there were also quarter and half hearts.

    Now i look at it again, i see that i fogot to set the animation speed to 0. Please note that.

  • kriand

    Yes, I'd like to avoid making so many "animations", as accounting for all the possibilities will take a lot of tedious work.

    However, if all else fails, I'll do it that way, haha...

    The thing is every Heart sprite has a nice Sine effect which I think would look weird if all Hearts are one Sprite.

    facecrime

    Hmm... Nice idea with the tilemap, though it would break my Sine effect too. I'm also drawing the hearts a bit closer to each other that the tilemap would allow I think.

    I like your idea of having a black heart under the red ones (Well, blue in my case). I'll try destroying the furthest red heart sprite and see if that works.

  • kriand

    facecrime

    Hey guys, Destroy on its own did not work, but I incorporated the idea of having the dark heart

    under the colored ones and used this:

    Player Health Points =/= HUD_Hearts.Count

    Hud_heart Pick furthest to (0, 24)

    Repeat Player.Health.LastDamagePoints times

    Every tick

    It works great! At least with some preliminary testing.

    The hidden dark hearts still show though, I may have to play a bit with their visibility.

  • leoncross

    here a quick made example with single sprites and sine behavior (C3 again):

    https://1drv.ms/u/s!Ap_-qxoGKbDcgz6BzgcnowHL3qvb

  • kriand

    Wow, you did it! Though the other method worked fine, the code is much cleaner. I incorporated the damage part and it works great!

    I even added the ability to stop the sine behavior on the dark hearts.

    I'll try adding the healing events and the Max HP powerups.

    Nice idea though, I thought of putting an index variable but I hadn't thought of matching the index of the heart sprite with the Player's HP...!

    Excellent!

    Thanks for making this!

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