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

2016/4/21

Scrolling world

1
2
3
4
danpost danpost

2016/5/2

#
GB309 wrote...
ok, so once I added it to an act method, my scrolling stopped working
Add the following to the act method:
super.act();
This is documented in the SWorld class.
GB309 GB309

2016/5/2

#
thank you sooooo much, ill try it
GB309 GB309

2016/5/2

#
YES! it works but is there a way of spawning some on the top left of the screen as well
danpost danpost

2016/5/2

#
There are several ways to have the spawn occur in different places. You could spawn them using a random angle some distance from the center of the world; you could spawn then at any random location in the world; you could spawn them near the left and right edges of the world (code acquiring x-coordinate value shown here).
int distFromEdge = 25;
int distBetweenSpawnLocs = getWidth()-2*distFromEdge;
int x = distFromEdge+(distBetweenSpawnLocs+Greenfoot.getRandomNumber(2))%(distBetweenSpawnLocs+1);
In the third line, if the random number generated was one, then zero will be added to the distance from edge for the spawning x-coordinate; otherwise the distance between spawn locations will be added to it.
GB309 GB309

2016/5/3

#
THANKS
danpost danpost

2016/5/3

#
GB309 wrote...
THANKS
danpost wrote...
... (code acquiring x-coordinate value shown here). < Code Omitted >
Wow -- did I do that??? More simply coded would be this for the third line:
int x = distFromEdge+distBetweenSpawnLocs*Greenfoot.getRandomNumber(2);
You need to login to post a reply.
1
2
3
4