Jump to content

Moving a sprite that is fixed to camera?


zoltan88
 Share

Recommended Posts

So I have the following code to draw my UI.

 

var ui = {
    menuBar: null,

    drawMenuBar: function() {
        var bar = new Phaser.Graphics(game, 0, 0);
        bar.beginFill(0xFF0000);
        bar.drawRect(0, 0, 600, 40);

        this.menuBar = game.add.sprite((window.innerWidth/2) - (bar.width/2), 0, bar.generateTexture());
        this.menuBar.fixedToCamera = true;
    },

    updateMenuBar: function() {
        this.menuBar.fixedToCamera = false;
        this.menuBar.x = ((window.innerWidth/2) - (this.menuBar.width/2));
        this.menuBar.fixedToCamera = true;
    },

    updateUi: function() {
        this.updateMenuBar();
    }
};

 

As you can see, to move the sprite in updateMenuBar I have to set fixedToCamera to false first, and then back to true. Is there a more elegant way to do this? If I just try to set menuBar.x to something, it wont move.

The above code solves my problem, I just thought it would be interesting to see if anyone else has a better solution (as Google has yielded me no satisfying answers) :).

Cheers!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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