I wonder how got make an object jump
can someone help me and send the code in this discussion
pls and thx


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // global private int ySpeed; // act ySpeed++; boolean onGround = false ; setLocation(getX(), getY()+ySpeed); Actor actor = getOneIntersectingObject(Actor. class ); if ((actor instanceof Ground) || (actor instanceof Platform)) { int dir = ( int )Math.signum(ySpeed); setLocation(getX(), actor.getY()-dir*(actor.getImage().getHeight()+getImage().getHeight())/ 2 ); ySpeed = 0 ; if (dir > 0 ) onGround = true ; } if (onGround && Greenfoot.isKeyDown( "up" )) ySpeed = - 15 ; |