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

2023/6/8

Delay a method on a single actor

FALAFFI FALAFFI

2023/6/8

#
Hello im trying to delay a method on a actor so the actor should walk over a route but not to quickly can someone help me with developing a delay that is like 500 milli seconds long but only goes delays the next action this is the code: public void Go(){ zweiVor(); //this makes him move forward delay(); //here he should wait for 500 milli seconds zweiVor(); delay(); zweiVor(); delay(); zweiVor(); turnleft(); //here he should turn left and after that move forward zweiVor(); } this is a part of the code in reality its much longer but how do I program now a delay that makes him delay before the next action?
danpost danpost

2023/6/8

#
FALAFFI wrote...
im trying to delay a method on a actor so the actor should walk over a route but not to quickly can someone help me with developing a delay that is like 500 milli seconds long but only goes delays the next action this is the code: << Code Omitted >> this is a part of the code in reality its much longer but how do I program now a delay that makes him delay before the next action?
I think you misunderstand the way greenfoot works. The act method is being called by greenfoot repeatedly at a regular rate (usually around 50 to 60 times a second). The rate has a "built-in" delay between act calls. Your action code should give what your actor should do at any moment. So, in pseudo-code, might look like this:
increment act counter;
if act counter is 30 (about half a second):
    move;
    increment move counter;
    if move counter is 4:
        turn left;
FALAFFI FALAFFI

2023/6/19

#
thank you
You need to login to post a reply.