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

 Share

  • Recently Browsing   0 members

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