never mind works. However all stationary sprites are leaving thier images behind infinitely.


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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | import greenfoot.*; public class Trex extends Actor { private int ySpeed; public Trex() { } public void setLoaction( int x, int y) {} public void act() { int groundLevel = 500 - getImage().getHeight()/ 2 ; boolean onGround = (getY() == groundLevel); if (!onGround) { ySpeed++; setLocation(getX(), getY()+ySpeed); if (getY()>=groundLevel) { setLocation(getX(), groundLevel); Greenfoot.getKey(); } } else // on ground { if ( "up" .equals(Greenfoot.getKey())) { ySpeed = - 16 ; setLocation(getX(), getY()+ySpeed); } } if (Greenfoot.isKeyDown( "down" )) { setImage( "duck.png" ); } else { setImage( "Trex.png" ); } } } |
1 | ... new Trex() ... |