I've created a fade and get an error:
This is my code:
Could someone take a look to see where I have gone wrong? Thanks in advance.
java.lang.IllegalArgumentException: The transparency value has to be in the range 0 to 255. It was: -1
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
* Write a description of class Transition here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Transition extends SharedMembers
{
private final GreenfootImage transition = new GreenfootImage(600, 400);
int fadeUpperLimit = 255;
int fadeLowerLimit = 25;
public Transition(String selection)
{
if (selection == "white")
{
this.xSpeed = 1;
transition.setColor(java.awt.Color.WHITE);
}
else if (selection == "black")
{
this.xSpeed = 5;
transition.setColor(java.awt.Color.BLACK);
}
transition.fill();
setImage(transition);
transition.setTransparency(fadeUpperLimit);
}
/**
* Act - do whatever the Transition wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
fade();
}
private void fade()
{
GreenfootImage transition = getImage();
transition.setTransparency(transition.getTransparency() - this.xSpeed);
if (transition.getTransparency() <= fadeLowerLimit)
{
getWorld().removeObject(this);
}
}
}
