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

2017/4/3

move animation use button

iban iban

2017/4/3

#
can you help me, i want move the animation use button rigth, left, i upload my scenario, can you see that and how i can do it?
danpost danpost

2017/4/3

#
iban wrote...
can you help me, i want move the animation use button rigth, left, i upload my scenario, can you see that and how i can do it?
Everything is changed from your first uploaded version. Also, now, your act method in your world class is empty! Where is all your codes?
iban iban

2017/4/3

#
i want make the game in android, the firts problem solved. now is new problem Mr.danspot. i want know how to move animation use button. i'm sory i very new in greenfoot.
iban iban

2017/4/3

#
please see my scenario. and give me example to move that animation. method animation already in that scenario. please mr.danspot :)
Nosson1459 Nosson1459

2017/4/3

#
Put the following in the Orang act method (only animation not moving):
1
2
3
4
5
6
7
8
9
10
11
12
if (Greenfoot.isKeyDown("up")) {
    up();
}
else if (Greenfoot.isKeyDown("down")) {
    down();
}
else if (Greenfoot.isKeyDown("right")) {
    right();
}
else if (Greenfoot.isKeyDown("left")) {
    left();
}
If you want it to move also then do:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//instance field
private int speed = 5;
 
// in act method
if (Greenfoot.isKeyDown("up")) {
    up();
    setLocation(getX(), getY() - speed);
}
else if (Greenfoot.isKeyDown("down")) {
    down();
    setLocation(getX(), getY() + speed);
}
else if (Greenfoot.isKeyDown("right")) {
    right();
    setLocation(getX() + speed, getY());
}
else if (Greenfoot.isKeyDown("left")) {
    left();
    setLocation(getX() - speed, getY());
}
danpost danpost

2017/4/3

#
Same as you had before for the buttons and same in the world class with the String field that the buttons set a value to. The world act method will should respond to the value of the String in a similar manner. The only difference is the action that is performed. Instead of moving, you are animating. Since I have lost context as far as what the different values you had returned, I will use English. First, you will need to move line 39 in the latar class to line 11 and add the following below that line:
1
public String orangDirection = "stop";
Next, in the act method of the latar class, add the following:
1
2
3
4
5
6
7
8
if ("left".equals(orangDirection))
{
    orang.left();
}
if ("right".equals(orangDirection))
{
    orang.right();
}
You can do similarly for "up" and "down" if needed.
iban iban

2017/4/3

#
nesson thank you for answeler. but i want contor use the button in world not use key int keyboard. :)
iban iban

2017/4/3

#
uh ok mr.danspot, i want try. you fry this method success :) . i very like and love greenfoot. i want stady and try all in greenfoot :)
iban iban

2017/4/3

#
Mr. can you see again my project? the code move already update but i not understand the call animation :(
danpost danpost

2017/4/3

#
If you understood the move code, then you should be able to understand the animation code given above.
iban iban

2017/4/3

#
hehe i understand key down use keyboard. i want try the code. :) sory i very new :)
iban iban

2017/4/3

#
yesss now work master.. thank you very much. thank you ver very very much master :) :D
You need to login to post a reply.