Hello,
I currently have two classes, World and Colors classes.
In world class, I basically created Colors object and invoking the method changeColor when space bar press. Clicking on space bar should switch between two imaged color states - blue image and red image. However, when I click the space bar once, it the image changes to blue then red very fast. A better word to describe it is "Lagging". I have to press the space bar multiple of times to toggle between the two colors.
The structure must be like this below:
Thanks guys!
public class myWorld{
private boolean isColorChanged = true; // default is blue
private Colors colorsObj1 = new Colors();
private Colors colorsObj2 = new Colors();
public void act(){
if (Greenfoot.isKeyDown("space")){
if (isColorChanged){
colorsObj1.setColor(false); // Change to red with false
colorsObj2.setColor(false);
isColorChanged = false;
}else{
colorsObj1.setColor(true); // Change to blue with true
colorsObj2.setColor(true);
isColorChanged = true;
}
}
}
}
public class Colors{
public void setColor(boolean colorFlag){
if (colorFlag){
this.setImage("blue.png");
}else{
this.setImage("red.png");
}
}
}
