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

2015/1/8

Spawning Objects at a fixed distance that scroll across the screen?

DiplomatikCow DiplomatikCow

2015/1/8

#
What would be an example of code that would allow someone to spawn an object at a fixed distance. I want it to spawn on the right side of the world (world size 800x600) and the object moves to the left.
danpost danpost

2015/1/8

#
With 'addObject(new ActorClassName(), xLocation, yLocation)', the 'xLocation' value would be 799 at the right edge of the world. 'move(-1);' ( or 'setLocation(getX()-1, getY());' ) in the act method of the actor class will make the actor move left.
DiplomatikCow DiplomatikCow

2015/1/8

#
Alright, thats all well and good now, but I need to keep spawning them forever, at a fixed distance apart from each other, at like, 50 lets say
DiplomatikCow DiplomatikCow

2015/1/8

#
So it can be like a constant wave of objects, yet still being 50 away from each other
danpost danpost

2015/1/8

#
In your world class, add an int instance object field for a spawn timer. In the act method of the world class, increment the timer, then check to see if it is 50 or not. If it is, reset the timer to zero and spawn an actor.
DiplomatikCow DiplomatikCow

2015/1/8

#
0.0 Im so confused.........Sorry :(
DiplomatikCow DiplomatikCow

2015/1/8

#
Ohhhh, I got it now, Thank you so much :D
You need to login to post a reply.