public class Test2 extends Actor
{
/**
* Act - do whatever the Test2 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private Actor valueBar;
private int value = 3600;
private int maxValue = value;
public Test2()
{
valueBar = new SimpleActor();
updateValueDisplay();
getWorld().addObject(valueBar,80,20);
}
public void adjustValue(int amount)
{
value += amount;
if(value<0) value=0;
if(value>maxValue) value=maxValue;
updateValueDisplay();
}
private void updateValueDisplay()
{
int wide = 100;
int high = 12;
GreenfootImage fullImg = new GreenfootImage(wide, high);
fullImg.setColor(Color.GREEN);
fullImg.fill();
GreenfootImage colorBar = new GreenfootImage(wide, high);
int percentage = wide*value/maxValue;
colorBar.drawImage(fullImg, percentage-wide, 0);
GreenfootImage img = new GreenfootImage(wide+4, high+4);
img.setColor(Color.WHITE);
img.fill();
img.setColor(Color.BLACK);
img.drawRect(0,0,wide+3,high+3);
img.drawImage(colorBar,2,2);
valueBar.setImage(img);
}
}
I'm trying to understand this progress bar from danpost
but I didn’t manage to make it work
it crashes with new SimpleActor in the constructor
and also with addObject, I tried to put getWorld () next to it, it seems to work but it doesn't compile with new SimpleActor
thanks for your help danpost

