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

2012/1/21

How to remove 1 object..

DMCGames DMCGames

2012/1/21

#
I'm not sure how to remove one object instead of all of them, because I'm using the method getWorld().removeObjects(getObjects(Block.class)); Any Ideas?
Builderboy2005 Builderboy2005

2012/1/21

#
getWorld().removeObject(object);
Where object is the reference to the object you want to remove.
Duta Duta

2012/1/21

#
Builderboy2005 wrote...
getWorld().removeObject(object);
Where object is the reference to the object you want to remove.
So in this case:
getWorld().removeObject(getWorld.getObjects(Block.class).get(0));
davmac davmac

2012/1/21

#
Duta: assuming you want to remove an arbitrary instance, then yes. However, you should probably check that there is an instance in the world first:
List l = getWorld().getObjects(Block.class);
if (! l.isEmpty()) {
  getWorld().removeObject(l.get(0));
}
Also note that 'getWorld' is a method and requires '()' behind it every time it is used.
Duta Duta

2012/1/21

#
Yeah, sorry about that - I typed it like ten minutes after I'd woken up..
You need to login to post a reply.