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

2013/11/16

Level boundary query

davemib123 davemib123

2013/11/16

#
Hi, I am revisiting my mario game to clean up some of the code. I've done part of it, but have got into a slight problem with the level boundary and ground methods. When the hero progresses to the next level, I get the error "Actor not in world". Could someone take a look and advise: http://www.greenfoot.org/scenarios/10009 Many thanks
Gevater_Tod4711 Gevater_Tod4711

2013/11/16

#
The problem is in your mario class. The method boundary() checks whether mario reaches the end of the level. If he reaches it the method setupLevel(int) int Level is executed which removes all objects from the world. So your mario get's removed from the world. But after removing your mario from the world the act method needs to be executed till the end. So after the execution of the method boundary() your checkGround() method is executed. This method uses the getOneObjectAtOffset method. And to execute this method your actor needs to be in the world. To fix this problem you could check if mario is still in the world before executing the checkGround() method.
davemib123 davemib123

2013/11/16

#
great. just what I needed. Thanks for the info :)
You need to login to post a reply.