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

2015/3/9

How can I make a part of my World not accessible for my actors?

CSBossmann CSBossmann

2015/3/9

#
Hi, here is another question for my greenfoot project. I want to put my score counter and the menu to the top of the world, but it is annoying that actors are spawning there or crossing the scores and menues. Does anybody know how I can make the actors don´t cross these parts of my world and my spawners don´t spawn there? Thank you!
danpost danpost

2015/3/9

#
Let us say that you do not want your actors to go to (or be spawned at) any location whose y-coordinate is less than 80. Then, that would be your world edge coordinate value for your actors. That is, at the end of the act method method for your actors, place the following line:
if (getY() < 80) setLocation(getX(), 80);
If you are using the 'atWorldEdge' method for anything, you can combine it with the condition above:
if (atWorldEdge() || getY() < 80)
If you are spawning actors randomly within the world, then you are probably using something like this:
int y = Greenfoot.getRandomNumber(getHeight());
If the minimum y-coordinate value is to be 80, then we start with 80 and subtract 80 from the random number generator:
int y = 80+Greenfoot.getRandomNumber(getHeight()-80);
CSBossmann CSBossmann

2015/3/10

#
Thank you! :D
You need to login to post a reply.