Jump to content

New to Phaser, trying to figure it out


Recommended Posts

I'm doing some very basic things to a) help me learn how to use phaser and B) slowly work on my first game, and I've currently run in to a snag I just can't figure out.



I've named the game itself game.js, and I'm writing the page itself in HTML. I've created a canvas for the .js to load in to, between a header and a footer. Everything loads up just fine and dandy, except for some reason the game.js creates a new canvas and places it under the footer. When I inspect the page, I can see the canvas I had created, but something somewhere is creating a new canvas just for the .js. How do I load the .js in to/on to the canvas I created?



If needed, I can upload everything I've got so far.

Link to comment
Share on other sites

Hey noodlesdefyyou!


This is not possible with the current workins of phaser.io.


However, you can specifiy the DOM element where you want phaser.io to place the game canvas.

This is done in the initiation class of "

"Phaser. Game" new Game(widthheightrendererparentstatetransparentantialias)

The "parent" parameter is what you are looking for.


Short example:

<!doctype html><html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">    <head>      <script>      var game = new Phaser.Game('800', '600', Phaser.AUTO, 'myGameTarget');      </script>    </head>    <body>       <div id="myGameTarget">        <!-- This is where you game canvas will be placed -->    </div>    </body></html>

Hope this is what you are looking for.

Link to comment
Share on other sites

var game = new Phaser.Game('800', '600', Phaser.AUTO, 'myGameTarget');


this is already in 'game.js'. would i need to remove that line from the .js, and call 'game.js' for 'mygametarget'?



edit: just figured it out. game loads where i wanted it to load. now i just need to center it :)


thanks for that! it was really bugging me!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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