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

2019/5/28

Making an Object Disappear When Clicked Using Coordinates

rb6333 rb6333

2019/5/28

#
Does anybody know how I would make an object disappear when it is clicked using coordinates? I have another object blocking it so it can't directly be clicked.
Super_Hippo Super_Hippo

2019/5/28

#
When the mouse was pressed, you can get the current location of the mouse with the use of the MouseInfo object. Then you can either check if the mouse X and Y coordinates are between xMin/xMax and yMin/yMax (if cellsize>1 at least) and remove your object then. Or you move an invisible helper object to the position of the mouse, get a list of all object in a small range with the getObjectsInRange method and if your object is one of them, remove it. (To see the methods and how they are used, visit the API with this link https://www.greenfoot.org/files/javadoc/ or by double clicking on Actor/World in Greenfoot.)
You need to login to post a reply.