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

2017/3/31

Remove Actor

Nooooob Nooooob

2017/3/31

#
How can I remove an actor at a certain place?
Super_Hippo Super_Hippo

2017/3/31

#
Get a reference to the actor with the 'getObjectsAt' method and then remove it.
Nooooob Nooooob

2017/3/31

#
Super_Hippo wrote...
Get a reference to the actor with the 'getObjectsAt' method and then remove it.
Like this?
getWorld().removeObject(getWorld().getObjectsAt(10, 10, x.class));
Super_Hippo Super_Hippo

2017/3/31

#
Almost. The getObjectsAt method returns a list of objects and not just one object.
Nooooob Nooooob

2017/3/31

#
Super_Hippo wrote...
The getObjectsAt method returns a list of objects and not just one object.
So, is it wrong? How can it return only one object?
Super_Hippo Super_Hippo

2017/3/31

#
if (!getWorld().getObjectsAt(10, 10, x.class).isEmpty())
{
    getWorld.removeObject(getWorld().getObjectsAt(10, 10, x.class).get(0));
}
Nooooob Nooooob

2017/4/1

#
One more question, what is this for?
Super_Hippo wrote...
.get(0))
Super_Hippo Super_Hippo

2017/4/1

#
It gets the first element in the list.
Nooooob Nooooob

2017/4/1

#
You need to login to post a reply.