How do I center a certain tile within tilemap (Solved)

0 favourites
  • 8 posts
From the Asset Store
slide the tiles to fill the board.60 awesome levels.
  • Hello everyone! I am currently using Tilemaps to make my map. I'm trying to move my map around until a specific tile is centered on the screen. For instance, when the player is selecting which portal they want to teleport to. I want to scroll that specific tile to the center of the screen.

    I am still new to tilemaps so I'm sure I'm missing something.

  • Don't move the tilemap - scroll the viewpoint using 'System> Scroll to' events.

  • Hi, I think I know what you want to do.

    First you need to make sure nothing else is setting the scrolling (not sure if you use scrolling to the player or if you have free scrolling in your project).

    Easiest way to do it is with some trigonometry, but you also need to store the scroll to points, either create two global variables called scroll2x and scroll2y or add those as instance variables to the player, maybe even create an object that is invisible called camera and have it store all kinds of variables related to scrolling mode. The reason why the latter might be more useful is that you can use the object as a storage for all kinds of boolean variables (like IsScrolling2Portal).

    Regardless, here is an example, because it was faster to make this than explains:

    https://www.dropbox.com/s/m9f65q4mn5yv0 ... .capx?dl=1

    It took me longer than expected to make this, mostly because I forgot the proper order of parameters for distance and angle functions. Mornings are not my best time of the day.

    I cheated a bit as I set scroll2x and scroll2y in the same event when picking the random location of the portal tile instead of searching for it in the tile map. Normally you will need to obtain it otherwise somehow, assuming your maps are not randomly generated that should be fairly easy to do.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Don't move the tilemap - scroll the viewpoint using 'System> Scroll to' events.

    I better explain myself better. My tilemap map has its own layer.

    7-etc.

    6-etc.

    5-skills

    4-Map

    3-UI

    2-game layer

    1-background1

    0-background2

    Can you "scroll to" using only a layer? I imagined that would only move the viewport and i need to move the tilemap within the map layer only

  • assuming your maps are not randomly generated that should be fairly easy to do.

    Yes my map is randomly generated. I have my tele's fully functional and already store locations of telerooms using variables. Just need to center a specific tile in the middle of the viewport.

    I am at work currently and will check out that example when i get home. Thanks.

  • > Don't move the tilemap - scroll the viewpoint using 'System> Scroll to' events.

    >

    I better explain myself better. My tilemap map has its own layer.

    7-etc.

    6-etc.

    5-skills

    4-Map

    3-UI

    2-game layer

    1-background1

    0-background2

    Can you "scroll to" using only a layer? I imagined that would only move the viewport and i need to move the tilemap within the map layer only

    Set parralax to 0,0 on the layers not containing objects that have locations on the map (so any UIs, minimap/worldmap windows etc.), that way the layers will not scroll when any scroll commands are issued.

    For finding the portal coords you will have a bigger challenge, depends how many portals you have per map. Personally I am doing a random map generator myself at the moment and I store all tilemap data within an array that uses Z-levels to store different info about a tile (such as bitwise sum for autotile, passability, fog of war visibility/discovered status etc.). So if you also use a similar method you could iterate through the map array until you find the right portal tile and upon finding it fire the whole scroll2portal function.

    The easier way would be to not have the portal as a tile but as a sprite object drawn/created on top of an empty tile. That way you could use regular picking via events which would make the whole thing easier. I use a similar solution for some objects myself, most notable doors as they are animated and need additional data such as open/closed state and will later use it for loot boxes.

  • Just need to center a specific tile in the middle of the viewport.

    https://www.dropbox.com/s/jblvvxwicuy4y ... .capx?dl=0

  • Just need to center a specific tile in the middle of the viewport.

    https://www.dropbox.com/s/jblvvxwicuy4y ... .capx?dl=0

    Awesome! Thank you. That was exactly what I needed.

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