With the Gravity the Actor should move just on an objekt under him.
How to make that?


1 2 3 4 5 | public boolean onGround() { Object under = getOneObjectAtOffset( 0 , getImage().getHeight()/ 2 + 2 , Ground. class ); return under != null ; } |
1 2 3 4 5 | public void fall() { setLocation (getX(), getY() + vSpeed); vSpeed += acceleration; } |
1 2 3 4 5 6 7 8 9 | public void checkFall() { if (onGround()) { vSpeed = 0 ; } else { fall(); } } |