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

2013/3/3

need help

Abdi Abdi

2013/3/3

#
so like you told me i included the following into my code to remove an object. public void act() { if (Greenfoot.isKeyDown("space")) { getWorld().removeObjects(getIntersectingObjects(Object.class)); i have just written the code to make a new, same object spawn into the world. but for that i need the boolean instruction that checks whether the object is removed or not. can someone write the boolean instruction that checks if the object has been removed or give me some tips?
danpost danpost

2013/3/3

#
It would probably be better to use 'Actor.class' (or the actual name of the class belonging to the object you want removed) instead of 'Object.class' in the above. However, if you are going to just re-introduce another object of the same type as the one removed, do not remove or add, but just re-locate the actor found:
if (Greenfoot.isKeyDown("space"))
{
    Actor actor = (Actor)getOneIntersectingObject(Actor.class);
    if (actor != null)
    {
        // get random x and y (or set x and y) for new location in world
        actor.setLocation(x, y);
    }
}
You need to login to post a reply.