My game has an actor who you control, the aim is to collect other objects to move up a level. Once all the objects are completed how can i get it to move on to the next level?
Thanks
if (getObjects(Collectable.class).isEmpty()) Greenfoot.setWorld(new NextLevelWorld());
Make 'Collectable' a sub-class of Actor, and all the collectable actors sub-classes of 'Collectable'. When all the collectable items have been collected, there should not be any left in the world; so go to the next level. Put the above line in the world class of each WorldLevel. Just replace 'NextLevelWorld' with the names of the worlds that you want to proceed to.
I suggested putting the line in the world classes, but if you happen to prefer it to be in an Actor class, then you need to prefix the method call to 'getObjects' with 'getWorld().'. This lets the compiler know where to find the method (it will assume it to be in the Actor class, otherwise). Nothing goes inside the parenthesis of the 'getWorld()' call. And you do not have to cast it to your sub-class of world, as the method is in 'World', not in your sub-class of world.
I still think the proper place for the line is in the act method of each world class that you have (without the 'getWorld().' prefixing).