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

  • 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! :-)

  • 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.

  • 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.

    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.

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