What is the easiest and fastest way to make a side-scrolling scenario? The problem is using addObject() and removeObject(), which makes the actors appear and disappear, which doesn't look so good in a side-scrolling scenario. The fastest way to fix it is to block the edges with a white rectangle but that has separate problems and I don't know the real normal looking way of doing it (I want it to side-scroll and to know how to do it not just to "cheat").
What is the easiest and fastest way to make a side-scrolling scenario? The problem is using addObject() and removeObject(), which makes the actors appear and disappear, which doesn't look so good in a side-scrolling scenario.
You can unbound the world by using the other World constructor provided by greenfoot. See the documentation here.
Thanks. I saw your side-scrolling scenario but I didn't understand it so much.
After you unbound the world, you can then add the actors outside of world bounds, to scroll into view; but, you must then take care that all actors the have been in the world are accordingly removed when moved out of view. If they remain in the world and you create an abundance of them (like shots, obstacles and enemies), then you are liable to create a lagging issue. They should be removed once their image is totally out of view:
if(getX() < -image.getWidth()/2) // scrolling right to left
// or
if(getX() >= getWorld().getWidth()+image.getWidth()/2) // scrolling left to right
For some actors that move, you may want to extend the distance allowed outside bounds to give them a chance to move back into view (maybe remove them when their range of movement has passed out of view).
btw how do u define the unbounded world and the bounded world
The documentation says this for the parameter:
bounded - Should actors be restricted to the world boundary?
So, being restricted, or a bounded world, would require a 'true' value for the parameter and unrestricted, or an unbounded world, would require a 'false' value.
What kind of side-scroller are you trying to create -- one that scrolls continuously regardless of any actor in the world or one that follows a specific actor? I will presume that this is for your Pengu project, in which case it follows an actor and scrolling occurs when the actor has passed a specific limit toward the right only. That is, no matter how far pengu is allowed left, no scrolling will occur (pengu would just be limited to some nominal x-coordinate value). So, anytime the world "sees" that pengu is on the right half of the screen, it should move all actors to the left the same distance so that pengu is back in the middle.