So I'm trying to make a message appear at the begining of every level ( here level counts, as having x score not by changing worlds), and I'm having no luck.
What I'm doing is the following:
1) Creating a messageBox class with the following code:
2) Creating the object on the enemies class (where the score counter is), or maybe I should be calling it on the world class?
What am I doing wrong here?
import greenfoot.*;
import java.awt.Color;
public class MessageBox extends Actor
{
GreenfootImage level1 = new GreenfootImage("Level 1", 12, Color.WHITE, Color.BLACK);
GreenfootImage level2 = new GreenfootImage("Level 2", 12, Color.WHITE, Color.BLACK);
GreenfootImage level3 = new GreenfootImage("Level 3", 12, Color.WHITE, Color.BLACK);
public Nivel()
{
setImage(level1); // just calling this because I was having problems with lag on the game
}
public void act()
{
if(enemies.score == 4) // the score here is declared in the enemies Class as a public static int so other classes can see it
{
setImage(level2);
}
else if(enemies.score == 6)
{
setImage(level3);
}
}
}public void level()
{
MessageBox level = new MessageBox();
getWorld().addObject(level, getWorld().getWidth()/2, 800);
if(timer > 5) { getWorld().removeObject(level);} // the timer is here so the message box can disapear after a certain period of time
}
