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

2019/3/30

delete object

plsFast plsFast

2019/3/30

#
i have two object (which can be placed more than once) and i want to write a method for one of them that deletes another object on the given koordinates my code is:
1
2
3
4
public void deleteObject(int x, int y)
{
getWorld().removeObject(objectname,x,y);
}
how do i do this?
Erasedsword Erasedsword

2019/3/30

#
I would try this public void deleteobject(int x, int y) { if(getX() == int x && getY()== (int y)) { getWorld().removeObject(objectname,x,y); } } Obviously use other values for the x and the y coordinates of the object your removing. Also this may not work seeing as I just started programming about 2 months ago, but try anyways
Super_Hippo Super_Hippo

2019/3/30

#
The World class has the method "getObjectsAt". It gets a list of all actors of a given class at given x/y coordinates. The following with remove anything from the world which is at (x|y).
1
getWorld().removeObjects(getWorld().getObjectsAt(x, y, null));
You need to login to post a reply.