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

2015/5/4

How to move only after keys pressed?

randombruh randombruh

2015/5/4

#
Hey guys so I have a project for Uni we have to make Pacman in greenfoot. And we use a Act method which means it loops continuously. So the problem is my character moves straight away. I only want it to move after I press a key how do I do this?
danpost danpost

2015/5/4

#
You need to show some attempted code at controlling the actor like you want. If you are trying to limit the execution of something, use an 'if' condition and place the code within the 'if' block. Refer to the Greenfoot class API for a method that detects key presses.
randombruh randombruh

2015/5/4

#
Ok thanks. Don't worry I wasn't trying to be lazy by not providing code, it's just I have no idea what to type.
yedefei yedefei

2015/5/4

#
for example ,if you want to press “up” key to trigger moving 10 steps ,you can write :
           if(Greenfoot.isKeyDown("up"))
              move(10);
You need to login to post a reply.