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

2012/3/1

keyboard control

Alfie5 Alfie5

2012/3/1

#
I want my actor to go up and down. I know I must use the if and whenkeyis up ect but after that what do i do? I have tried move and turn but it doesn't work. Should I be using a specific integer?
danpost danpost

2012/3/1

#
In the code for that actor you want to go up and down, in the act() method, put your if statement with your turn() and move() statements. If after trying that, and fidgiting with it, and you still cannot get it to work, post your code with a specific question of what you are trying to do.
Alfie5 Alfie5

2012/3/2

#
I am trying to get a person to move to right, left, up, down when the following key is pressed. I can get left and right but I can't get up and down to work. If I use the below it just turns. If I separate the move and put it after the curly bracket when i press run it just does the move command. { if (Greenfoot.isKeyDown("up") ) { turn(-4); move(4); }
Duta Duta

2012/3/2

#
int speed = 3;
if(Greenfoot.isKeyDown("up"))
    setLocation(getX(), getY() - speed);
if(Greenfoot.isKeyDown("down"))
    setLocation(getX(), getY() + speed);
if(Greenfoot.isKeyDown("left"))
    setLocation(getX() - speed, getY());
if(Greenfoot.isKeyDown("right"))
    setLocation(getX() + speed, getY());
Alfie5 Alfie5

2012/3/3

#
Thank You
You need to login to post a reply.