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

Get help using Construct 2

Post » Sat Jan 21, 2017 2:31 am

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.
Image
Last edited by SEGamestudio on Sat Jan 21, 2017 6:12 pm, edited 4 times in total.
B
44
S
13
G
7
Posts: 32
Reputation: 5,628

Post » Sat Jan 21, 2017 10:23 am

Don't move the tilemap - scroll the viewpoint using 'System> Scroll to' events.
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 242
Reputation: 2,306

Post » Sat Jan 21, 2017 10:35 am

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.
B
15
S
6
Posts: 85
Reputation: 1,195

Post » Sat Jan 21, 2017 2:14 pm

mrtumbles wrote: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
Last edited by SEGamestudio on Sat Jan 21, 2017 3:25 pm, edited 3 times in total.
B
44
S
13
G
7
Posts: 32
Reputation: 5,628

Post » Sat Jan 21, 2017 2:24 pm

Pulstar wrote: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.
B
44
S
13
G
7
Posts: 32
Reputation: 5,628

Post » Sat Jan 21, 2017 3:59 pm

SEGamestudio wrote:
mrtumbles wrote: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.
B
15
S
6
Posts: 85
Reputation: 1,195

Post » Sat Jan 21, 2017 4:51 pm

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

https://www.dropbox.com/s/jblvvxwicuy4y ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat Jan 21, 2017 6:12 pm

99Instances2Go wrote: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.
B
44
S
13
G
7
Posts: 32
Reputation: 5,628


Return to How do I....?

Who is online

Users browsing this forum: Fenix18, Lancifer and 52 guests