adding a health bar

Get help using Construct 2

Post » Mon Oct 10, 2011 3:39 am

hey guys ,

was wondering what to do to insert a health bar ,
so far I can only add a global variable then get the system to subtract from that number ....
i think a health bar looks a lot better .
can anybody suggest how to or
where to find the answer ?

thanx a lot >
B
30
S
8
G
9
Posts: 30
Reputation: 8,693

Post » Mon Oct 10, 2011 4:10 am

Hey Carminie, I am new here but i have been programming for a few years. My suggestion is make a health bar image that has a set of animations that each are at a different point in the health bar. Then when you lose heath or gain health you can set the animation to a different frame. With this you can also incorporate an instance variable that represents the amount of health you have.


[|||||||||]- first frame
[|||||||| ] - second frame
[||||||   ] - third frame
..... - other frames
[        ] - empty health (dead)


there may be a better way or even a better way of explaining this.

sorry if this is not helpful.
B
5
G
3
Posts: 25
Reputation: 1,275

Post » Mon Oct 10, 2011 4:58 am

You can get construct to change the width of a red (or any color you like) square sprite to match the players health.

I.E an event that every tick "set width to players.health"

Have a look at the space blaster game demo that's where I got the info from.

Hope this helps.

knight007au2011-10-10 05:08:16
B
4
G
2
Posts: 6
Reputation: 1,217

Post » Mon Oct 10, 2011 1:10 pm

wow ! thank you for prompt reply guys !
i ll give it a shot maybe later today , maybe tomorrow
my g/f thinks i spend to much time "playing" games
and recording music .
thank God she s leaving for a week tomorrow
I m never going to get married !!
I ll update u guys asap
B
30
S
8
G
9
Posts: 30
Reputation: 8,693

Post » Mon Oct 10, 2011 10:31 pm

[QUOTE=carminielloz]
thank God she s leaving for a week tomorrow
I m never going to get married !!

[/QUOTE]

This is a good kid right here.
"Enter The Grump Monk"
B
12
S
4
G
5
Posts: 40
Reputation: 3,934

Post » Tue Oct 11, 2011 3:33 am

B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Post » Tue Oct 11, 2011 6:29 am

to piggyback of knight007au

create a small tick -> import tick as a tiled BG
create a variable for tick -> health
       set a value for health (whatever width you want i.e. 100)

system -> on start of layout -->
     tick -> set width to tick.health
     tick -> set variable health to tick.health (now the current value     of heath is stored)

sprite -> on collision -->
     tick -> set width to tick.health - 10 (or however much you want the health bar to be reduced by)
     tick -> set variable health to tick.health

tick -> health (less than or equal to) tick.width
     sprite -> destroy

there may be a simpler way, but this 1 is functional

injoy!





B
16
S
2
G
1
Posts: 43
Reputation: 1,473

Post » Tue Oct 11, 2011 12:25 pm

thank you very much boys n girls !!
i haven t had time to try all these nice things out yet
as it has been a hectic week
( yes I broke up with my g/f in the end so
no i m not going to get married )
sorry for bringing up personal life stuff in a forum that should only be dedicated to game making I guess
i ll let you guys know
a big thank you to everybody for taking your time to help
B
30
S
8
G
9
Posts: 30
Reputation: 8,693

Post » Thu Oct 20, 2011 5:53 pm

[QUOTE=komes] Hey Carminie, I am new here but i have been programming for a few years. My suggestion is make a health bar image that has a set of animations that each are at a different point in the health bar. Then when you lose heath or gain health you can set the animation to a different frame. With this you can also incorporate an instance variable that represents the amount of health you have.


[|||||||||]- first frame
[|||||||| ] - second frame
[||||||   ] - third frame
..... - other frames
[        ] - empty health (dead)


there may be a better way or even a better way of explaining this.

sorry if this is not helpful.[/QUOTE]


I like this idea. Expanding upon it, I'm wondering to set the full health bar as the sprite. Then set each different health % as a seperate animation.

Then as the instance variable changes (sprite takes damage) have it call the corresponding animation.

Example:
health(instance variable)= 10 then set health (sprite) animation to 100percent

health = 6 then set animation to 60percent

B
22
S
9
G
3
Posts: 202
Reputation: 3,645


Return to How do I....?

Who is online

Users browsing this forum: WhosWho and 22 guests