This site requires JavaScript, please enable it in your browser!
Greenfoot back
browny87
browny87 wrote ...

2016/1/30

Movement in greenfoot

browny87 browny87

2016/1/30

#
hey guys ive been using the other discussions to try and get my character moving, ive tried the following but it doesn't work!; public Character1() { if(Greenfoot.isKeyDown("right")) { setLocation(getX()+3, getY()); } if(Greenfoot.isKeyDown("left")) setLocation(getX()-3, getY()); if(Greenfoot.isKeyDown("down")) setLocation(getX(), getY()+3); if(Greenfoot.isKeyDown("up")) setLocation(getX(),getY()-3); } tried it both ways, any ideas?
danpost danpost

2016/1/30

#
The movement code needs to be in the act method of the class, not in the constructor of the class.
You need to login to post a reply.