Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » health bar
- deck26
-
1000+ posts
health bar
Create, for example, ten clones. Give each a cloneID (local variable, set by sprite before it creates each clone) and only show the clone if the health is at least as high as its value. Move the sprite a few pixels each time you create a clone so they are spaced correctly.
Alternatively each clone could have, for example, a green block costume and a red block costume and show the red one if health is lower than cloneID, otherwise the green one.
Alternatively each clone could have, for example, a green block costume and a red block costume and show the red one if health is lower than cloneID, otherwise the green one.
- Play-pause-games
-
100+ posts
health bar
an simpler and more effecient solution would be to creat a sprite with say 10 costume for 10 states o fthe hp bar
then create a variable and make the sprites code like this
then make sure the first costume is the least full health and the last is the most full - so it displays properly
i use this in a lot of my project so im sure you can find an example there
then create a variable and make the sprites code like this
then make sure the first costume is the least full health and the last is the most full - so it displays properly
i use this in a lot of my project so im sure you can find an example there
- deck26
-
1000+ posts
health bar
I agree @Play-pause-games solutiont is simpler, I was distracted by you mentioning clones.
- Slam-
-
100+ posts
health bar
I have tried…
Further I do not know …
Last edited by Slam- (Aug. 30, 2018 03:13:05)
- deck26
-
1000+ posts
health bar
Why not go for @Play-pause-games solution?
You haven't given each clone a unique cloneID which is essential for my version. Set cloneID to 1 and after you create each clone change the sprite's copy of the variable (it has to be for this sprite only so each clone inherits the value the sprite's copy had when the clone was created).
You haven't given each clone a unique cloneID which is essential for my version. Set cloneID to 1 and after you create each clone change the sprite's copy of the variable (it has to be for this sprite only so each clone inherits the value the sprite's copy had when the clone was created).
- Nuclearpuppy
-
36 posts
health bar
Make a health bar sprite with 10 costumes (lets say 100 is the most hp you can have). Whenever the heath is, say, >90 and <100, the costume is costume 2 (with one less interval). When the health variable is >80 and <90, switch to costume 3 and so on. Base it all off Play-pause-games' script and expand from there. 

- deck26
-
1000+ posts
health bar
That should be close but try changing x by 10 instead of setting it to 10. All your clones are in one place.
- RokCoder
-
1000+ posts
health bar
This was my example project for a similar question. It uses a curved health bar but the same principle could be used for a standard health bar (but sliding the mask sprite across the health bar rather than rotating it as in the example project). It's not better or worse than the previously suggested solutions - just another different option.
- Slam-
-
100+ posts
health bar
Not bad, but this health bar will not work for my project.
My script, as it seems to me, is closest to the desired result. But there is a problem, with a change in health, all clones hiding
My script, as it seems to me, is closest to the desired result. But there is a problem, with a change in health, all clones hiding
- _nix
-
1000+ posts
health bar
That's because once the sprite hides, it is never told to show again. You might want to do something like this instead, in the “when I start as a clone” block: Not bad, but this health bar will not work for my project.
My script, as it seems to me, is closest to the desired result. But there is a problem, with a change in health, all clones hiding
- deck26
-
1000+ posts
health bar
Better to use wait untils so you're not endlessly telling Scratch to show the sprite when it's already showing.That's because once the sprite hides, it is never told to show again. You might want to do something like this instead, in the “when I start as a clone” block: Not bad, but this health bar will not work for my project.
My script, as it seems to me, is closest to the desired result. But there is a problem, with a change in health, all clones hiding
forever
show
wait until hp < clone ID
hide
wait until not hp < clone ID
end
- Discussion Forums
- » Help with Scripts
-
» health bar