i don't have any code yet but i cant think of anything that could work any thoughts!!


1 2 3 4 5 6 | gravity--; setLocation(getX(), getY() - gravity); // set the location so it appears the actor is falling if (getY() >= 450 ) // this is just what I have so at a certain point the actor stops falling, otherwise they would just fall off the screen { gravity = 1 ; } |
1 | setLocation(getX(), getY()+vSpeed); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | private void moveVertically() { boolean onGround = false ; // will be changed if needed within the method before jumping vSpeed++; // change in vertical speed due to gravity setLocation(getX(), getY()+vSpeed); // moving vertically Actor actor = getOneIntersectingObject(Actor. class ); // class can be made more specific if (actor != null ) // collision? { int dir = ( int )Math.signum(vSpeed); // -1 if rising, 1 if falling (0 should not trigger collision) vSpeed = 0 ; // kill vertical speed if (dir > 0 ) onGround = true ; // falling? -- on ground setLocation(getX(), actor.getY()-dir*( 1 +actor.getImage().getHeight()+getImage().getHeight())/ 2 ); // adjust position of player } /** if using bottom edge of world as ground surface * else * { * if (getY() > getWorld().getHeight()-getImage().getHeight()/2) * { * vSpeed = 0; // kill vertical speed * onGround = true; // on ground * setLocation(getX(), getWorld().getHeight()-getImage().getHeight()/2); // position player * } * } */ if (onGround && Greenfoot.isKeyDown( "up" )) vSpeed = - 12 ; // adjust initial jump speed as needed } |