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

2014/1/18

Spawn within a range

JustMe JustMe

2014/1/18

#
First of all sorry for the spelling mistakes i hope you'll understand what i mean ;) My question is how i can spawn these object within a range (with coordinates i guess) without coming back at places where they can't be. i've tried different things but now i'm stuck. This is what i have now. Thanks public void act() { if (spawnCounter++ > 625) { addObject(new Thief(), Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight())); spawnCounter = 1; addObject(new Fire(), Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight())); spawnCounter = 1; addObject(new Accident(), Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight())); spawnCounter = 1; } }
danpost danpost

2014/1/18

#
With what you have now, you will have three objects (a thief, a fire, and an accident) spawn (at the same time) each at random places in the world every ten seconds or so. How you want to limit where these objects spawn has not been given, which is the main problem with the post. Also, you only need to reset the 'spawnCounter' field to one once within the 'if' block.
You need to login to post a reply.