Discuss Scratch

cs3711034
Scratcher
11 posts

Coding a health bar

Kinda self-explanatory. I know that there's the simple option of creating a costume for every possible amount of health you could have, but that's a little too time-consuming in my opinion. What's the simplest way anyone here knows how to code a functional health bar, that can work with any amount of health points for a character?
EXPERlENCE
Scratcher
54 posts

Coding a health bar

Use pen, in a fashion like this:

define health bar (health)
clear
pen up
go to x: (-50) y: (0)
set pen color to [#808080]
set pen size to (14)
pen down
go to x: (50) y: (0)
pen up
go to x: (-50) y: (0)
set pen color to [#FF0000]
set pen size to (10)
pen down
go to x: ((-50) + (health)) y: (0)
pen up

I'm pretty sure something of this fashion would work pretty well. You simply run the block whenever the health value changes and it'll draw it to the screen. Keep in mind though that this will draw to the background, so behind any other sprites
Pixilized
Scratcher
100+ posts

Coding a health bar

Pen can only appear behind sprites, so any other sprites will cover it up. I recommend this Health Bar tutorial by griffpatch, that uses costumes, but only three.

--Robinflight--
Scratcher
36 posts

Coding a health bar

cs3711034 wrote:

Kinda self-explanatory. I know that there's the simple option of creating a costume for every possible amount of health you could have, but that's a little too time-consuming in my opinion. What's the simplest way anyone here knows how to code a functional health bar, that can work with any amount of health points for a character?
You don't have to draw every single costume Y'know– it works if you duplicate a full costume then delete parts of it bit by bit
If that's what you're thinking of when you say drawing, then you should probably just go with the pen

>> hai there !! >D<
- I'm Robinflight! -
★ I like making games about Warrior Cats ( updating every day ) and making art <3 ★
>> . Warrior Cats ! ( and also a bunch of other things I'm obsessed w/. …Rob and Linden, anyone ??… )
>> . check out my profile!
★ robin signing out…★

broadcast [ Keep Calm and Scratch On v]

Powered by DjangoBB