Jump to content

Camera following player and always rotated in direction player is looking?


CtlAltDel
 Share

Recommended Posts

For a topdown view game I am looking for a way to make sure the camera is always rotated so the player on screen always faces up. If that makes sense.

 

I tried setting the game.world.pivot point to the player and then rotate the world and player accordingly, that basically works somewhat but the following breaks and the player is nolonger centered.

 

A minimalistic example of the problem: http://connected.dnd.utwente.nl/~wouter/phasermap/

 

Use arrow keys to move the arrow and shift-left and shift-right to rotate. Ideally I would have the arrow at the center bottom of the screen and have the map pivot around that. The map currently does pivot around the arrow, but it seems setting the pivot to something other than the default makes the scale of the rendered player different. The camera still seems to follow at the correct speed, but the arrow dissapears from screen.

 

Anyone have a good solution that might work?

Link to comment
Share on other sites

Figured out a solution. (url in first post is an updated version)

 

I use 2 groups. one containing the player, and one containing the backdrop.

I then set the pivot and position to the player position in update. Apparantly setting a group pivot point will also change it's position..... Something I did not expect.

 

Right now the map will rotate around the arrow fine. With some compensation for the rotation I should be able to make the player arrow move naturally when rotated as well, but that's something I'll tackle later.

 

It would be sooo much easier if Phaser could support a rotation on the camera, that way I could just rotate the camera to always face the correct direction....

Link to comment
Share on other sites

  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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