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

2013/7/6

I am trying to make it so the main player hits the finish line and it changes to level 2 it says it cannot find symbol numberOfObjects();

qsapp.3 qsapp.3

2013/7/6

#
what is the code and what do you put it under to change levels as soon as the main player hits an object
Gevater_Tod4711 Gevater_Tod4711

2013/7/6

#
Well if you want to change the level when you player touches an object you should use something like this:
//in your player class;
if (getOneIntersectingObject(EndObject.class) != null) {
    //you reached the end object; But you'll have to change the EndObject.class to your classname;
    //here you can start the new level;
    Greenfoot.setWorld(new Level2());//just a guess;
}
Using this you can check whether your actor touches the end object. But to help you to change the level or fix the bug you have it would be great to know the code you are using.
danpost danpost

2013/7/6

#
You are probably trying to use 'numberOfObjects' in a class that extends Actor. Since that method is part of the World class API, you need to apply the method to a world object. The Actor class method 'getWorld' will return the world that the actor is in. So,
int objectCount = getWorld().numberOfObjects();
will work in your actor class.
You need to login to post a reply.