This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

danpost
danpost presents ...

2012/2/5

Progress bar/Health bar class

Bar class with no editing required. All needed methods are available to suit most needs.

Download, and while NOT running, right click on the bar and experiment with some (or all) of the methods provided.

Also, check out some sub-classes you can use with the bar (to allow it to be adjustable; to make a switch; or to make a timer display) located in the following scenario:

http://www.greenfoot.org/scenarios/5677

15760 views / 76 in the last 7 days

23 votes | 0 in the last 7 days

Tags: demo with-source bar danpost progress-bar support-class health-bar

This scenario is a member of: Support Classes by danpost


open in greenfoot
Your browser does not support the canvas tag.
Liamb2179Liamb2179

2014/4/22

I figured it out based on a different discussion thread you answered haha, I was trying to add the bar object into the world from the constructor of the unit.
danpostdanpost

2014/4/23

@Liamb2179, it is possible to do so; but, the world object must be passed to the constructor (directly or indirectly) like a method argument. What I mean by indirectly, is an Actor object ( 'Actor actor' )that is in the world could be passed instead because it has a reference to the world that can be retrieved with 'actor.getWorld()'.
SullyFishSullyFish

2014/5/14

how would I make the bar go down by making a different class touch a different class?
SullyFishSullyFish

2014/5/14

it doesnt find bar.subtract in my other class
SullyFishSullyFish

2014/5/14

public void hit(){ Actor actor = getOneObjectAtOffset(0, 0, Ennemies.class); if(actor != null) { Bar.subtract(1); } }
danpostdanpost

2014/5/14

@SullyFish, start a discussion thread, show how you create the bar and how you are trying to use the bar (code posting is better in discussion threads).
SullyFishSullyFish

2014/5/14

nvm sorry I found it
A new version of this scenario was uploaded on 2017-01-20 23:18:50 UTC
A new version of this scenario was uploaded on 2017-10-16 02:02:20 UTC
Nate2002Nate2002

2018/11/29

This is pretty cool

See all comments

Want to leave a comment? You must first log in.

Who likes this?

tjoepapke JerHowden Ariadia hugtvy SPower arinb kikumaru818 ndrwdslv FlyingRabidUnicornPig dianefayeparajes Poli solokeh rhddpcks Cocky davemib123 erdelf limefortheworld SkyLark tylers Gazzzah