How to have horizontal scrolling tilemap with static character

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Mison

I’m trying to make a Scramble style game which is a horizontal landscape scroller with a static character that can move independently up/down/left/right. I have made a tilemap which has the landscape but I don’t know how to move (scroll right to left) the tiilemap while keeping the player positioned in the middle of the screen. The player should be able to collide with the landscape.

I can scroll the tilemap by putting a camera on the player and making the player move (position.x +=1) but the tilemap scrolling needs to be independent of the player moving.

Any help/suggestions with just pointing me in the direction of tackling this is really appreciated. I’ve tried experimenting with viewports etc for a few days and I’m completely stuck.

Since posting this I have discovered that the tilemap can be scrolled(moved) using its transform. Is this the best way to go about the game type I’m designing?

Mison | 2020-02-03 23:07

:bust_in_silhouette: Reply From: denxi

Instead of scrolling the tilemap, you could just have your character and camera constantly moving in the direction you want them to travel, as well as recording your player movements. Instead of having the camera focused on the player, have it focused on a separate Node2D, which will be the middle of your screen. You can also have a moving collision box around the camera to prevent the player from leaving the game screen.

The reason to do it this way, rather than by scrolling the tilemap, is that you’d also have to scroll every single other “non-moving” object in the game. It’s much easier to just move the camera and player simultaneously.

Thank you very much for replying. I’ve managed to get this working as you described.

Mison | 2020-02-04 21:43