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

2024/1/10

Limiting Actors' Movement On The X-axis.

yesineedhelp yesineedhelp

2024/1/10

#
I'm currently making a game and I made it so that actors spawn randomly along the x-axis as of right now. However, I want the actors to spawn only within a certain x-axis. Say my world/super is 900,500. How do I make it so that the actors only spawn from 100-800 along the x?
danpost danpost

2024/1/10

#
yesineedhelp wrote...
I'm currently making a game and I made it so that actors spawn randomly along the x-axis as of right now. However, I want the actors to spawn only within a certain x-axis. Say my world/super is 900,500. How do I make it so that the actors only spawn from 100-800 along the x?
The starting value is 100 and the range is 700 (actually, to include both 100 and 800, 701):
int spawnX = 100 + Greenfoot.getRandomNumber(701);
You need to login to post a reply.