Jump to content

Putting game on website


newgame
 Share

Recommended Posts

Hi everyone! I'm having trouble with publishing the phaser game on the website. I do not want to publish a html file with the game in an iframe.
I would like to place javascript code directly to the existing web page. At first i placed this code to the <head>:
<script async="" type="text/javascript" src="/phaser.min.js"></script>
And then added <script type="text/javascript" src="game.js"></script> exactly in the place of the page where i would like the game to be.

But in this case, the game is displayed in the footer, and I found there this tag:
<canvas width="800" height="600" style="display: block; touch-action: none; -webkit-user-select: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); width: 800px; height: 600px; cursor: inherit;"></canvas>

What should i do to make phaser insert the tag <canvas> in the place of the page where i added javascript?

Sorry for my English and thanks to all!

Link to comment
Share on other sites

You'll notice that the 4th parameter in the Game constructor (http://phaser.io/docs/2.4.4/Phaser.Game.html) is "parent".

As the documentation states, you can pass in an actual HTML Element where your game will be inserted, or you can pass the ID of an element in as a string.

For example:

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

This will create the game and insert it into the element with ID "my-game". So if you had a div like this:

<div id="my-game"></div>

The game would be created inside of that div. You can then place the div wherever you want.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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