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

2012/5/3

progress bar to follow actor

tylers tylers

2012/5/3

#
how do i get this progress bar http://www.greenfoot.org/scenarios/4114 to follow an multipull actors.
Duta Duta

2012/5/3

#
I'm not sure what you mean by "multipull actors", but here's an idea on how to follow an actor.
public class ProgressBar {
	Actor following;
	//Other fields
	
	public ProgressBar(Actor following) {
		this.following = following;
		//Rest of constructor
	}
	
	public void act() {
		followActor();
		//Rest of act()
	}
	
	private void followActor() {
		if(following != null
		&& following.getWorld() != null) {
			int x = following.getX(),
				y = following.getY() - following.getImage().getHeight()/2 - getImage().getHeight()/2;
			setLocation(x, y);
		}
	}
	
	//Other methods
}
I may well have mis-interpreted what you're asking, but its worth a shot.
danpost danpost

2012/5/3

#
What do you mean by 'multipull' and in exactly what why do you want the progress bar to follow the actor?
tylers tylers

2012/5/3

#
what i meant was i wanted to show the health of each bug on the screen.
danpost danpost

2012/5/3

#
Create a constructor in Bug that recieves a Bar object, send a different one to each as you create them. You will need an instance Bar variable in the Bug class to hold the bar specific for each bug. Then each bug can control their own Bar object.
You need to login to post a reply.