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

2014/8/13

Delay function

thepangolin thepangolin

2014/8/13

#
Can i delay just one actor and not the whole scenario?
lordhershey lordhershey

2014/8/13

#
yes, but you will have to write it yourself in the act method, I usually do something like this:
//class member variable
long starttime = System.currentTimeMillis();

public void act()
{
  long endtime = System.currentTimeMillis();

  if((endtime - starttime) < 3000)
  {
    //We have not waited 3 seconds yet so exit
    return;
  }

  //reset the start time
  starttime = System.currentTimeMillis();

  //rest of act
}
Gamezocker Gamezocker

2014/8/13

#
you can make:
public class YOURCLASS
{
    int delay;

    public void act() 
    {
        if(delay < 15)
        {
            delay++;
            return;
        }
        else
        {
            delay = 0;
            // What should delayed do here. example:
            Code1();
            Code2();
        }
    }
}
Now all have a delay what is in the act method
thepangolin thepangolin

2014/8/13

#
thank you :)
Gamezocker Gamezocker

2014/8/13

#
ok
You need to login to post a reply.