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

2014/5/13

How to stop an actor while letting the other actors keep moving?

Discovery530 Discovery530

2014/5/13

#
Hello friends, I'm trying to make an if statement that basically says if they are at the edge of the world they stop. Is there a simple command to make an actor stop and letting the other actors resume their scripts? I'm sure you can do this with a line of code but is there a command for this?
lordhershey lordhershey

2014/5/13

#
Do you want the actor to stop forever and just sit there? If so, just make a Boolean variable call it something like NeverMoveAgain, set it to false upon construction. When the edge of the world is detected set this variable to true. In the act have this
Public void act()
{
    if (NeverMoveAgain)
        return;

... Rest of routine here ...
}
danpost danpost

2014/5/13

#
If you use a World constructor 'super' call with only three int arguments, 'super(int, int, int)', then your world is bounded and if your actors only move horizontally and vertically, they will stop automatically at the world edges. However, half of their images will be cut off by the edge of the window. You could use 'getImage().getWidth()' and divide it in half and then use an 'if' statement for each side edge -- 'if (getX() < halfWidth)' and 'if (getX() > getWorld().getWidth()-halfWidth)' for the horizontal edges. Then do similar for the vertical directions. That would keep the entire image of your actor in view, stopping it at the edges.
Discovery530 Discovery530

2014/5/13

#
lordhershey wrote...
Do you want the actor to stop forever and just sit there? If so, just make a Boolean variable call it something like NeverMoveAgain, set it to false upon construction. When the edge of the world is detected set this variable to true. In the act have this
Public void act()
{
    if (NeverMoveAgain)
        return;

... Rest of routine here ...
}
Pretty smart actually :) I'll try that when I get back on my program
danpost wrote...
If you use a World constructor 'super' call with only three int arguments, 'super(int, int, int)', then your world is bounded and if your actors only move horizontally and vertically, they will stop automatically at the world edges. However, half of their images will be cut off by the edge of the window. You could use 'getImage().getWidth()' and divide it in half and then use an 'if' statement for each side edge -- 'if (getX() < halfWidth)' and 'if (getX() > getWorld().getWidth()-halfWidth)' for the horizontal edges. Then do similar for the vertical directions. That would keep the entire image of your actor in view, stopping it at the edges.
Dannggg thats pretty clever
You need to login to post a reply.