Better scrolling

We can make camera follow certain object, but it’ll follow it indefinitely. How to make camera stop on the level bounds so things outside level won’t be shown?

There is an other action which is “Center camera on object within limits”.

You can also reproduce this action yourself by using a “Camera” object.
Make the camera follow the “Camera” object, and then set “Camera” object at the same position as your hero ( for example ). Add then some events to ensure that “Camera” object position is bound, like this one:

Conditions : "Camera" object X position is < 50 Acitons : Do =50 to "Camera" object X position

Yeah, but both actions fails for me. I trying to achieve that my game will stop scrolling on bounds of background. It stops scrolling, BUT it is scrolled too much already and around background sprite there is empty space:

Red line is bound of background and arrow points where it should be.

New_object is background and moveck is “pencil”.


I think you should work on this action a bit so bounds would be really bounds :wink:.

Try this. (175 KB)

It’s a hackish solution and I want clean solution. Every gamemaking tool has good scrolling which doesn’t leave space around bounds of level. Your solution still leaves some pixels of empty space (16-24 pixels) though it’s closer to what I consider good “Center camera on object within limits”.

Thanks for your work to help me. We’re one step closer - now 4ian should implement your method in “Center camera on object within limits” action.

There’s 20 pixels because I made it so (debugging). Just change the limits in camera positioning part, and it should work the same.
I don’t think there’s any less hackish way than this one. The current “Follow camera within bounds” is made for case when movement on both axis must stop together.

In your case, the camera must continue to follow the x axis, even when the y axis mustn’t move.
There’s two others ways to do so :

  • Making the backgorund as big as the game resolution (= no scrolling at all)
  • Putting obstacles in the scene, so the followed object will bump into them, preventing the camera to move further (one-screen-large walls in mario bros for example)

My solution is to match x-movements of the camera to x-movements of the object, and y-movements of the camera to x-movements of the object, but independently from each others. Then you have a smooth scrolling in both direction. Then I use dummy invisible sprites to prevent the object to get out through collision detections.
The trick is to separate the management of the object from the management of the camera. The object must move between bounds, that are larger than those restraining the camera.

Notice I didn’t use any physics routines. Which might be troublesome later for a “realistic” plateforme-like game…

Still thank you for your effort. I may use it in my game, though I’ll wait till next version of GD to see if 4ian will implement this solution in the “Center camera on object within limits”. That’d be awesome.

The action works but the limits coordinates works with the center of the view : the limits limits the center of the view. :wink:

Yeah, I know. I just find that a bug (though for 96,56% it was made on purpose so didn’t post it in bugs section). I like probably other people expected it to limit scrolling on edges of screen (like scrolling of level works in other game makers), not on screen center.

Hi, I’m trying to rework your code so it’ll work depending on game’s resolution, not on fixed values, like before. Unfortunately, I don’t understand what second values do here:

(already removed borders using Trial&Error™ technology tough :wink: and it don’t use collision mask objects anymore, now it calculates position based on scene “Limits” variables, one for X,Y,Height and Width)

4ian, could you rework this action, so it limits to bounds of screen, not screen center?