Jump to content

Group fixed to the camera only in x axis


blackbox
 Share

Recommended Posts

Hi, 

for my specific goal I need to have a group of components which are fixed to the camera, but only in x axis. What I mean is that if a player moves left or right, the group moves with the player (is fixed to the camera), but when the player moves up or down, the components behave like if they were part of the world (not fixed to the camera). What's the best (or any) way to implement this within Phaser?

Thanks!

Link to comment
Share on other sites

To do this, I would ignore the fixed to camera functionality, and instead use Phaser.Camera.focusOnXY() inside your update loop to move the camera with your group.  Something like this:

function update() {
    game.camera.focusOnXY(myGroup.x + myGroup.width/2, 100);
}
        

That snippet should focus on the center of the group in the x direction, but keep the y coordinate always at 100.  This is basically how Phaser.Camera.follow() works under the hood anyways.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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