zoltan88 Posted November 3, 2017 Share Posted November 3, 2017 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 More sharing options...
Skeptron Posted November 3, 2017 Share Posted November 3, 2017 Use cameraOffset.x / y http://phaser.io/docs/2.4.6/Phaser.Component.FixedToCamera.html#cameraOffset zoltan88 1 Link to comment Share on other sites More sharing options...
zoltan88 Posted November 3, 2017 Author Share Posted November 3, 2017 2 hours ago, Skeptron said: Use cameraOffset.x / y http://phaser.io/docs/2.4.6/Phaser.Component.FixedToCamera.html#cameraOffset Fantastic and quick answer. This works perfectly, thanks! : ) Link to comment Share on other sites More sharing options...
Recommended Posts