Can't figure out how to prevent scrolling beyond bounding sprites (in a pixel-perfect manner)

0 favourites
  • 8 posts
From the Asset Store
Particles support animations, collisions, effects and etc.
  • Hello.

    This is what I'm looking to achieve:

    • I want to use 16x16 sprites (square tiles) as bounding objects that my camera can't scroll past under any circumstances.
    • In other words, the camera should never be able to scroll so far that it's able to show even a pixel beyond the edges of these bounding tiles.
    • This also means that If I have a room that is smaller than the viewport, the camera should stay right in the center of the room.

    I've been using Construct for about 10 years and I've spent the past four hours trying to figure this out using various approaches (sprite collision, offset algorithms, clamp etc.) and even though I feel like my solutions should work, they just don't.

    If anyone can tell me how to achieve this (i.e. the actual specifics rather than a vague suggestion) then I would be very grateful.

    Thanks for taking the time to read! :-)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • this is what I would do...

    create Min and Max sprites for X and Y, and clamp the camera coordinates to their locations.

    https://www.rieperts.com/games/forum/LimitCamera.capx

    this puts the limit markers where to stop the camera... you can still see beyond that so you have to calculate where to put them. if you dont want to see anything beyond the edge of the layout, you have to put these far enough in to accomplish that.

    it you want to set these at the limit of what you see, then you have to calculate an offset from them based on the viewport size.

  • this is what I would do...

    create Min and Max sprites for X and Y, and clamp the camera coordinates to their locations.

    https://www.rieperts.com/games/forum/LimitCamera.capx

    this puts the limit markers where to stop the camera... you can still see beyond that so you have to calculate where to put them. if you dont want to see anything beyond the edge of the layout, you have to put these far enough in to accomplish that.

    it you want to set these at the limit of what you see, then you have to calculate an offset from them based on the viewport size.

    That doesn't solve the issue, because it confines the camera to a specific bounding box. I'm talking about disallowing the camera from scrolling past *any* bounding tile that's been mapped in my tile grid.

  • if multiple limiting tiles are visible, how is the camera supposed to know which ones apply? and which direction to limit the camera?

    can you post a sample file so we can see how you are placing the tiles?

  • if multiple limiting tiles are visible, how is the camera supposed to know which ones apply? and which direction to limit the camera?

    It's supposed to limit it in all directions, and it *should* in my opinion work by checking for overlapping at an offset. I just can't seem to get it to work.

    can you post a sample file so we can see how you are placing the tiles?

    An image would illustrate it better:

    The red shape is the viewport. The yellow tile in the center is the camera. The purple shapes are bounding tiles. The camera should in no way be able to proceed past the bounding tiles if the edge of the viewport collides with it.

  • Bump.

  • One way I do a similar thing is I make a grid of sprites that are camera points and I ScrollTo the camera points depending on which one is closest to the player. This way I completely control the camera bounds.

    Not sure what your game looks like, would probably help if you made a project mockup of what you are trying to do. But it seems like AllanR had the answer, you just need to dynamically pick which tiles are relevant as your min/max depending where the viewport is in your layout. Some sort of nearest calculation should do it where you are always changing those values depending where the player is in the layout.

    Assuming you are doing and abrupt scrollTo it should work without any overlap.. but if you are using some sort of lerp for your camera, there will be bleed since if you suddenly change the min/max and are currently out of the bounds, it will then need to lerp to the new max/min and you will see it do so.

  • Here is my version:

    dropbox.com/s/tvy796w1hhe68g7/BoundedScroll.c3p

    (I hope I understood the task correctly)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)