This site requires JavaScript, please enable it in your browser!
Greenfoot back
LonelyCreeper
LonelyCreeper wrote ...

2013/1/2

How do you let one actor call for the action of another one?

LonelyCreeper LonelyCreeper

2013/1/2

#
In the game that I'm working on, when an actor performs a certain action, a message box is supposed to show. The message box is another actor in a different class. How do I get this to work?
danpost danpost

2013/1/2

#
Usually, it is something like:
getWorld().addObject(new MessageBox("message"), xLocation, yLocation);
LonelyCreeper LonelyCreeper

2013/1/2

#
Thanks, but now theres another problem. When the actor calls the method, more than one message box appears. they just layer on top of each other.
actinium actinium

2013/1/2

#
Thanks, but now theres another problem. When the actor calls the method, more than one message box appears. they just layer on top of each other.
This is probably because your Act() method keeps calling the worlds addObject method and drawing messagebox's. You need to set a condition to do what you want.
LonelyCreeper LonelyCreeper

2013/1/2

#
how exactly do i write a code for that?
actinium actinium

2013/1/2

#
private boolean messageShown;

public void act()
{
    checkMessage();
}

private void checkMessage()
{
     if (messageShown == false)
     {
       getWorld().addObject(new MessageBox(),x,y);
       messageShown=true;
     }
}
LonelyCreeper LonelyCreeper

2013/1/2

#
Thanks dude! It worked :D
You need to login to post a reply.