Lined up sprites as lives counter

Get help using Construct 2

Post » Tue Apr 05, 2016 6:26 pm

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?
B
15
S
2
G
3
Posts: 45
Reputation: 2,638

Post » Tue Apr 05, 2016 6:32 pm

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

Code: Select all
On Function "hud_health" -> Destroy "heart"
    Repeat player.health times -> Create object "heart" at X + (loopindex * spacing), Y


You call the function whenever the player takes damage, collects a life and at the start of the layout
Last edited by 7Soul on Tue Apr 05, 2016 6:48 pm, edited 1 time in total.
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Post » Tue Apr 05, 2016 6:40 pm

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)

Code: Select all

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)



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 ;-)
The Things you can create is only limited by your imagination. If you don't have the skills then use your motivation as a natural force to exceed all expectations. Chadori RebornXD
B
65
S
21
G
90
Posts: 1,124
Reputation: 59,862


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests