Jump to content

Slightly improved platformer camera mechanic


Jonchun
 Share

Recommended Posts

I thought I'd share what I did for my platformer camera. The object is to always have your character at the center of the camera (like tight follow), but still allow some dead area to move around. The following used in the update loop in combination with this.camera.follow(this.player, Phaser.Camera.FOLLOW_PLATFORMER); creates a slow scroll to center the character in the center of the camera whenever he stops moving. Let me know if you guys have a better solution!

 
   
    if(this.player.body.velocity.x == 0)    {        if(this.camera.x < (this.player.x - this.camera.width * .5) - 1)        {            this.camera.x += 1;        }        else if (this.camera.x > (this.player.x - this.camera.width * .5) + 1)        {            this.camera.x -= 1;        }    }    if(this.player.body.velocity.y == 0)    {        if(this.camera.y < (this.player.y - this.camera.height * .5) - 1)        {            this.camera.y += 1;        }        else if (this.camera.y > (this.player.y - this.camera.height * .5) + 1)        {            this.camera.y -= 1;        }    }
Link to comment
Share on other sites

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...