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

2013/4/2

How check if a specific object is still in the world ?

TomazVDSN TomazVDSN

2013/4/2

#
Is there any way to check if a specific object is still in the world ?
Here's an example:
public Actor findActor(Actor find)
{
    ArrayList<Actor> actors= (ArrayList<Actor)/*World*/.getObjects(Actor.class);

    for (Actor a : actors)
        if(a.eqauls(find))
             return a;
    return null;
}

public boolean actorInWorld(Actor find)
{
    return findActor(find) != null;
}
danpost danpost

2013/4/2

#
If you have a reference to the actor object ('find' in the case above), just use:
if (find.getWorld() != null)
TomazVDSN TomazVDSN

2013/4/2

#
Gentlemen, thank you ! When I get home from work, I will test it. By the way this is the best "forum" I have been. Greenfoot have great people and have great Code !
JetLennit JetLennit

2013/4/2

#
I know!! This place is the best!
You need to login to post a reply.