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

2017/3/16

HOW TO ADD ACTORS EVERY 3 SECONDS

fxrrxr fxrrxr

2017/3/16

#
hI! Does anyone know how to add one actor every 3 seconds
danpost danpost

2017/3/16

#
fxrrxr wrote...
hI! Does anyone know how to add one actor every 3 seconds
There was just a discussion on this using 10 seconds here.
fxrrxr fxrrxr

2017/3/16

#
ooops i didnt see im so sorry thanku !!
fxrrxr fxrrxr

2017/3/16

#
wait sorry last question i already figured out how to add every 3 seconds but how do i add a different actor?? do i use the same code in a different class?
danpost danpost

2017/3/16

#
fxrrxr wrote...
wait sorry last question i already figured out how to add every 3 seconds but how do i add a different actor?? do i use the same code in a different class?
How often are these other actors to be added? You could probably just modify the current code to suit.
fxrrxr fxrrxr

2017/3/16

#
my first actor appears every 4 seconds. the second actors every 3 seconds. i have a couple more actors that will either appear at the same rate as the said actors or not
danpost danpost

2017/3/16

#
fxrrxr wrote...
my first actor appears every 4 seconds. the second actors every 3 seconds. i have a couple more actors that will either appear at the same rate as the said actors or not
Okay, you can have the timer repeat every 720 cycles (about every 12 seconds). Then:
1
2
if (timer%180 == 0) ... // spawns every 3 seconds
if (timer%240 == 0) ... // spawns every 4 seconds
hi i'm sorry for barging but i'm also having a slightly similar goal, is this code correct
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
private void checkForSpawning()
 
{
     
    //spawnTimer = (spawnTimer+1)%50; // repeat every 10 seconds (about)
    //(spawnTimer == 0) // at each timer reset
    if (timer%180 == 0)
    {
         addObject(new A(), 150, Greenfoot.getRandomNumber(1));
    }
}
 
{
    spawnTimer = (spawnTimer+1)%40; // repeat every 10 seconds (about)
    if (timer%240 == 0) // at each timer reset
    {
         addObject(new C(), 250, Greenfoot.getRandomNumber(2));
    }
}
danpost danpost

2017/3/16

#
No. More like this:
1
2
3
4
5
6
private void checkForSpawning()
{
    spawnTimer = (spawnTimer+1)%720;
    if (spawnTimer%180 == 0) addObject(new A(), 150, 0);
    if (spawnTimer%240 == 0) addObject(new C(), 250, 0);
}
fxrrxr fxrrxr

2017/3/16

#
THANK U SO MUCH IT WORKED
OH MINE AS WELL! Thank you!
You need to login to post a reply.