Is there a pointer to a greenfoot scenario somewhere that uses graphics to draw the sprite dynamically, every time act is called? I've tried a couple of runs at this and something seems to be redrawing the original sprite image over and over again so that I see the custom graphics before the scenario starts but not after it starts. Something like this:
---8<---8<---8<--- MyActorIsNotWorking.java ---8<---8<---8<---
public void act()
{
// Add your action code here.
drawShip();
checkForKeyboardEvents();
checkForWorldEdge();
}
public void drawShip()
{
GreenfootImage original = getImage();
GreenfootImage image = new GreenfootImage(original.getWidth(), original.getHeight());
int diameter = Greenfoot.getRandomNumber(30);
int x = Greenfoot.getRandomNumber(image.getWidth());
int y = Greenfoot.getRandomNumber(image.getHeight());
int r = Greenfoot.getRandomNumber(256);
int g = Greenfoot.getRandomNumber(256);
int b = Greenfoot.getRandomNumber(256);
Color c = new Color(r, g, b);
image.clear();
image.setColor(c);
image.setTransparency(128);
image.fillOval(0, 0, diameter, diameter);
image.drawLine(0, 0, 10, 10);
image.drawLine(0, 0, 0, 10);
image.drawLine(0, 0, 10, 0);
image.drawLine(10, 10, 0, 10);
image.drawLine(10, 10, 10, 0);
image.drawLine(10, 10, 10, 0);
setImage(image);
}
---8<---8<---8<--- MyActorIsNotWorking.java ---8<---8<---8<---
I'm not finding much on techniques for this in the greenfoot book or in the discussion forums. I would love to start students on their own scenarios making their own little versions of a game like Captain Forever (http://www.captainforever.com/captainforever.php) or derivatives but I'm not out of the starting block doing anything besides displaying images for a sprite. Any thoughts?
Thanks.
Best regards,
-- DanG

