frenetikm Posted July 15, 2015 Share Posted July 15, 2015 Hi, I'm making a game, and in my boot.js file I'm doing:this.scale.pageAlignHorizontally = true;this.scale.pageAlignVertically = true;for display in center of the page. The problem is when the page load, I see the game at top left of the page for less than a second, and after in the center... Can somebody tell me what is the cleanest way to avoid this ? (show the game only after it has been centered) Link to comment Share on other sites More sharing options...
vez Posted July 16, 2015 Share Posted July 16, 2015 I would set the canvas or the DOM element containing the canvas to display:none; and then in the js do something like this:if (this.scale.pageAlignHorizontally && this.scale.pageAlignVorizontally) { document.getElementById("DIVcontainingGame").style.display = "block";} Link to comment Share on other sites More sharing options...
Skeptron Posted July 16, 2015 Share Posted July 16, 2015 Or maybe you can center it with plain CSS directly? vez 1 Link to comment Share on other sites More sharing options...
frenetikm Posted July 16, 2015 Author Share Posted July 16, 2015 @Skeptron: the purpose was to keep the alignment with Phaser, if I do it via CSS where is no interest to keep this functions in my code @vez: thanks, I think I'll do it like this way, I hoped a cleanest way Link to comment Share on other sites More sharing options...
Skeptron Posted July 16, 2015 Share Posted July 16, 2015 I get it, but I'm not sure it's worth doing it with Phaser. With CSS, you're sure the canvas will be aligned before running any JS code (at least I think!), and the code to write is really simple. But do as you please =) Link to comment Share on other sites More sharing options...
drhayes Posted July 16, 2015 Share Posted July 16, 2015 I second Skeptron's advice: if you really want the canvas centered before your game runs you'll need to center it using CSS and not depend on Phaser doing it for you. Link to comment Share on other sites More sharing options...
Recommended Posts