A problem with multiple layers, layout size and scroll to x

  • Hi all, I hope this makes sense, I would post a .capx but it's a bit hard to isolate from my game at the moment, but if anyone thinks they can help and wants to take a look I will do so. Will try to describe first.

    My game has several different layers, one of them is a global layer called 'MAP' which is shown when the user presses the M key. When the M key is pressed it pauses the game and it unhides the map/menu layer.

    The map/menu layer contains three screens worth of information, so it can't all be displayed at once. Instead I give the player the option to press the left and right arrows and it will smoothly scroll to the relevant point on the screen using lerp(scrollx, target, etc). Because I can't target a specific layer to scroll to, it does the whole layout - it doesn't really matter because the map screen covers the game area so the player would be unaware of this, BUT using this method there is quite a limitation, in that if the current game layout is smaller than the area needed for the 3 menus it can't scroll to them.

    So if I have 3 screens wide to fill with my map/menu it takes up 1920 pixels but if the game layout is smaller than that eg 1280 pixels, the scrollto won't work at any range outside of the layout, even if the layout the global map layer is on is larger than this and set to unbounded scrolling.

    If I could turn unbounded scrolling on and off with events, or if I could target a scrollto location on a specific layer I might be able to come up with a workaround, but there doesn't seem to be a way to as far as I can see. I could just make sure all of my layouts are at least the width needed for the map/menu - but it will be a lot more mucking about, less easy to maintain - as I'm doing a metroidvania style game with many different rooms/layouts with a map etc, I don't really want to have to pad layouts out like that if I don't need to.

    Anyone got any suggestions, or better ways I could go about this?

    Many thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would not use layout scrolling for the map. As you said, if you have multiple levels, each with a different size, the map would be limited to the level's size, which could be smaller than the map.

    Instead, I would suggest implementing custom scrolling events for the objects that make up your map. You didn't tell how you built your map. But I would guess it's made of sprites?

    You can add all these sprites to one family, then, in the event sheet, implement a function to scroll the family. It's not that hard. Here is an idea :

    You will need a reference point on your map, so create a sprite and call it "MapMarker". Place it on your map layer at the top-left position. All coordinates on the map will be computed from this point.

    Give your map layer parallax values of (0,0) so we completely disable the built-in parallax/scrolling system.

    Problem: How to scroll to a point on the map.

    Here is what we know :

    • At all times, we know the position of the marker on the layout. Let's call it Pm
    • We also know the point at which we're looking at right now, let's call it Point 1.

    Point 1 in map space will be equal to (Screen Width/2, ScreenHeight/2) - Pm

    So in order to scroll from Point 1 to Point 2, you need to translate all the objects on the map (including the marker), by a vector equal to Point2 - Point 1

    Just my humble opinion.

  • Zed2100 - thanks very much! It sounds like it could be a good solution. Perhaps sticking the objects into a family and scrolling that is the way to go. The map is made up of an array, 2 tilemaps and a position indicator so could be wrapped up in a family and scrolled without too many problems I think. Now that I think about it I might just be able to pin everything to an invisible bar and scroll that. Thanks for your response, I was probably approaching the issue from the wrong angle.

  • You can even create a custom behavior using the javascript sdk if you know how to. However, for 2 tilemaps, the custom scrolling shouldn't take more than a few events.

    I'm facing similar challenges with my Parallax Backgrounds behavior. Not only do I have scrolling, but also zooming, parallaxing and screen wrapping in all directions. If you succeed in implementing the solution, I would love to know about it.

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