Jump to content

Camera position accordingly to tilemap


zetsubou
 Share

Recommended Posts

Hi! I have an issue with camera position accordingly to tilemap. My goal is supermario-like platformer. I create the game instance, but tilemap(that i created from JSON) is 2400 px in height, so it does not fit at the screen.
Seems like i can spawn objects out of the current screen bounds, but cant reach these with camera. Cameras origin is located at the very top of the screen(0,0), however anything spawned is far beyond from it at the bottom(i tried to use a viewport, but just getting nothing changed).
Can I rotate camera somehow? I tried: 

this.cameras.main.viewPort(window.innerWidth, window.innerHeight, 200, 1800)

Also tried to focus main camera on the player(failed it either).

 

Link to comment
Share on other sites

Nevermind, I can, but it disappears immediately and camera flies away at the top outside of game bounds. 
Can't figure out why camera, if i do: 

this.physics.add.existing(ground);

flies away even out of the game bounds(as i said above). Now it looks too confusing)
UPD: I have to expand game world bounds cause nothing is drawn outside of it(what does make sense, but it seems to strongly affect performance). 

Link to comment
Share on other sites

If you have physics bodies with collideWorldBounds=true they will be immediately moved inside the physics world bounds if they were created outside it.

If you change the camera bounds such that the camera is outside them them it will immediately move to the nearest edge.

If you have the camera follow a sprite it will move immediately (unless lerped) to center on the sprite.

I would try to get everything in your game positioned as you want first before configuring the camera at all, because it can get confusing once the camera starts moving.

Edited by samme
different bounds
Link to comment
Share on other sites

15 hours ago, samme said:

If you have physics bodies with collideWorldBounds=true they will be immediately moved inside the bounds if they're created outside it.

If you change the camera bounds such that the camera is outside them them it will immediately move to the nearest edge.

If you have the camera follow a sprite it will move immediately (unless lerped) to center on the sprite.

I would try to get everything in your game positioned as you want first before configuring the camera at all, because it can get confusing once the camera starts moving.

That's how it works! Now it makes much more sense for me, than before. Thank you!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...