Hi,
For a game we need to make a system where objects need to spawn in left of the World and move to the right, and spawn with some delay. So an object spawns first, than another, and then again another, just until Gameover. But how am I able to do this? I am able to spawn a object on the left and I tried to make the spawn system work but it just doesn't. This was the basic code so far (for spawning a fly on the left):
I saw a similar topic on this issue and I copied it in my code and it didn't work. This is the code.
Can somebody help me with this issue? Thanks
1 2 3 4 5 6 7 8 9 10 | public class PortWorld extends World { public PortWorld() { super ( 800 , 600 , 1 ); addObject( new Fly(), 10 , Greenfoot.getRandomNumber( 135 )+ 235 ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | public class PortWorld extends World { private int spawnRate; public PortWorld() { super ( 800 , 600 , 1 ); checkSpawning(); } private void checkSpawning() { spawnRate = (spawnRate+ 1 )% 100 ; if (spawnRate == 0 ) addObject( new Fly(), 10 , Greenfoot.getRandomNumber( 135 )+ 235 ); } } |