My scenario is using the Greenfoot.setWorld(World world) method to change between world, but this is a very instant change. I would like to have a smooth change using a fader. My change world method is very simple at the moment and looks like this.
My fader looks like this:
Now I would like some kind of loop that made the fade go from 0 to 255 before the method "Greenfoot.setWorld(((BattleWorld) getWorld()).myWorld);" is executed, but I can't figure out how.
Any help is appreciated and thanks for your time.
Greenfoot.delay(100); getWorld().addObject(new Fader(), getWorld().getWidth() / 2, getWorld().getHeight() / 2); Greenfoot.setWorld(((BattleWorld) getWorld()).myWorld);
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; /** * Write a description of class Fader here. * * @author (your name) * @version (a version number or a date) */ public class Fader extends Actor { public int fadeLevel = 0; /** * Act - do whatever the Fader wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { } public Fader() { fade(0); } public void fade(int f) { if (f > 255) { f = 255; } else if (f < 0) { f = 0; } GreenfootImage fade = new GreenfootImage(600, 400); Color fadeColor; fadeColor = new Color(0, 0, 0, f); fade.clear(); fade.setColor(fadeColor); fade.fillRect(0, 0, 600, 400); setImage(fade); } }