Screen-by-screen scrolling

How can I do that? I mean scrolling as seen in first Zelda, Metroid, Jet Set Willy or VVVVVV. Of course easiest would be to make scene for each sector, but then I would end up with gazillion scenes. So I’d like to use some event code. Can you help me?

Just change the camera position like this : ( assuming width of the window is 800 and height is 600 )

Set Camera X position to floor(Hero.X()/800)*800 Set Camera Y position to floor(Hero.Y()/600)*600

Thanks. More universal solution:
Camera x to floor(object.X()/ScreenWidth())*ScreenWidth()
Camera y to floor(object.Y()/ScreenHeight())*ScreenHeight()

There’s a drawback though of this method. When screen position changes, character stays on previous one for a moment, which in case of The Missile can lead to accidental crashes (of missile, not game’s). I want game to scroll when object is out of current screen completely. I wish there would be “Object is outside of camera zone” or whatever.

It’s because we’re using the origin of the object as coordinates.
You can instead use its center :

[code]Camera x to floor(object.PointX(Centre)/ScreenWidth())*ScreenWidth()
Camera y to floor(object.PointY(Centre)/ScreenHeight())*ScreenHeight()

or ( The second version works for any object and not only for Sprite objects )

Camera x to floor( (object.X()+object.Width()/2)/ScreenWidth())*ScreenWidth()
Camera y to floor( (object.Y()+object.Height()/2)/ScreenHeight())*ScreenHeight()[/code]

I tried with center too - it’s even worse (delay between changing screen and appearing of missile on second screen is even bigger). If we would have “Object leaves camera’s viewport” condition, I’d just execute screen changing logic under it.

So put a point a the rear of the missile and use the coordinates of this point.
Thus, the screen will change when nearly the entire missile will be outside the first screen. :slight_smile: