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

2014/4/6

removing objects after hitting world

Greenfootnoob Greenfootnoob

2014/4/6

#
hi... i just wanted to know the code for making an object disappear after touching the Worlds edge. can anyone help?
danpost danpost

2014/4/6

#
The world is an two-dimensional array of cells. The width of the world is acquired by the World class method 'getWidth' and the height is acquired by the World class method 'getHeight'. So the four edges are horizontally at '0' and 'getWidth()-1' and vertically at '0' and 'getHeight()-1'. The World class method 'removeObject' in the world class will make an object 'disappear'. The Actor class method 'getWorld' will return the world the actor is in. The actor class methods 'getX' and 'getY' return the location coordinates of the actor within the world. Those are the pieces. You put them together testing the conditions and then performing the action if needed.
You need to login to post a reply.