Lined up sprites as lives counter

0 favourites
  • 3 posts
From the Asset Store
Make a displayed number gradually increase or decrease, making an impression of a real-time counting.
  • In the game I'm working on, I have implemented a lives counter, showing the number of lives as a number on a corner of the screen. However, I'd like this lives cointer to be a row of sprites, starting at 5 and with the number of sprites decreasing as lifes are lost. How would something like this be implemented?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You want a function with a loop on a subevent that loops "player health times", and it creates a heart at position + (loopindex * spacing). The function also destroys all hearts before the loop

    On Function "hud_health" -> Destroy "heart"
        Repeat player.health times -> Create object "heart" at X + (loopindex * spacing), Y
    [/code:2bnmffbq]
    
    You call the function whenever the player takes damage, collects a life and at the start of the layout
  • Let's say that you have 3 as capacity of life.

    Make a Global Variable named "Life"

    Set (LifeSprite) as your sprite life counter (Image you see as life)

    Add Instance Variable Number named "Index" to (LifeSprite)

    Global Variable Number = "Life"
    
    {Group : + Life}
    *Compare variable "Life" > 0
              ------> Create Object (LifeSprite) (64, 64)
              ------> Set (LifeSprite) instance variable "Index" to 1
    
    *Compare variable "Life" > 1
              ------> Create Object (LifeSprite) (128, 64)
              ------> Set (LifeSprite) instance variable "Index" to 2
    
    *Compare variable "Life" > 2
              ------> Create Object (LifeSprite) (192, 64)
              ------> Set (LifeSprite) instance variable "Index" to 3
    
    {Group: - Life}
    
    *Compare variable "Life" < 3
              *Pick by comparison (LifeSprite.Index = 3)
                           --> LifeSprite [Destroy] or [Fade out]             (Note: Your choice if fadeout or destroy)
         
    *Compare variable "Life" < 2
              *Pick by comparison (LifeSprite.Index = 2)
                           --> LifeSprite [Destroy] or [Fade out]             (Note: Your choice if fadeout or destroy)
         
    *Compare variable "Life" < 1
              *Pick by comparison (LifeSprite.Index = 1)
                           --> LifeSprite [Destroy] or [Fade out]             (Note: Your choice if fadeout or destroy)
    
    [/code:360clcjw]
         
    You might also want to set the layer of the sprite counter parallax to 0 and add an anchor behavior for your LifeSprite.
    That's it. Happy Game making
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)