kontra icon indicating copy to clipboard operation
kontra copied to clipboard

TileEngine camera centering and functionality

Open crimson-med opened this issue 1 year ago • 1 comments

I had a question on how does the TileEngine.sx renders for camera view?

I'm trying to create a camera that centers the player on the screen. In my update I used:

tileEngine.sx = character.x
tileEngine.sy = character.y

However it is not centering the player. (red) Furthermore it is also impacting the collisions as it offsets all the coordinates in some way.

Is it possible to get more insight on how the camera for the tileEngine works?

Video of the issue:

https://drive.google.com/file/d/1wUSULJRo881fX1H-BKy_-AoB6gq5Iypx/view?usp=sharing

As can be seen at the beginning the red character hits invisible wall which is actually the top of the left building. (big offset)

crimson-med avatar Sep 22 '22 13:09 crimson-med

The tileEngine sx/sy is the top-left corner of the tileEngine view, so if you set it to the character position it will try put the character to the top-left corner (if it can). You can see a full example of a centered player in the camera tileEngine example.

For collision, which part is it impacting? If it's the player and the tile set, then you'll probably want to add the player to the tilemap. The example shows this as well.

straker avatar Sep 23 '22 01:09 straker