I am making a game in which the player has to evade incoming objects, however the objects get stuck on the edge of the word.
Thanks for taking the time to read my question.


1 2 3 4 5 6 7 8 9 10 11 | public boolean isOffScreen() { if (getX() < 0 - getImage().getWidth()/ 2 || getX() > getWorld.getWidth() + getImage().getWidth()/ 2 || getY() < 0 - getImage().getHeight()/ 2 || getY() > getWorld().getHeight() + getImage().getHeight()/ 2 ) { return true ; } return false ; } |
1 2 3 4 5 6 7 8 | public void act() { if (isOffScreen()) { getWorld().removeObject( this ); } //rest of your act code. } |
1 | if (getX() == 0 ) getWorld().removeObject( this ); |