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

2021/12/3

Random spawn enemy

Gengar360 Gengar360

2021/12/3

#
How do I make it so when an enemy spawns it spawns in a random location on one side of the game?
danpost danpost

2021/12/3

#
Either (for left side):
int x = Greenfoot.getRandomNumber(getWidth()/2); // or getWorld().getWidth() if in Actor subclass)
or (for right side):
int x = getWidth()/2+Greenfoot.getRandomNumber(getWidth()/2); // same note (but for both getWidth()s)
You need to login to post a reply.