Hello Guest

Author Topic: Center player to viewport  (Read 3369 times)

selltrib

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Center player to viewport
« on: April 01, 2014, 02:33:46 pm »
Hi All,

I bought this tool kit today and so far I'm really very impressed, but I've hit one issues which I'm kind of stuck on.

I'm doing a top down test game, got my tile map loaded, got my orthographic camera following the player. and also got the camera to stop at the map bounds.

All perfectly working fine (very easy to do)

However once my player sprite has moved to the very edge of the map and the camera has become locked, when they start head back, the player sprite is handover to what ever side I walked too. I'm not sure how to get the camera to stay clamped until the player is back into the center of the viewport, then the camera can start to follow the player again.

I'm sure this is something simple and I'm just to tired to see it, but does have have any hints at to what I'm trying to do





unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Center player to viewport
« Reply #1 on: April 01, 2014, 11:17:18 pm »
You will need to work out the bounds of the tile map, and clamp the camera to the bounds of the tile map, so it doesn't exceed the bounds. The logic will have to be specific to your game - basically you want to clamp to the player + bounds first, and then clamp that to the tile map bounds.

selltrib

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Center player to viewport
« Reply #2 on: April 02, 2014, 11:53:50 am »
Hey,

Thanks for the reply. I've kind of got it working, but it's not pretty. will come back to it later on when i've made some progress on other things.