Jump to content

Use the phaser in a specific canvas element


Recommended Posts

Hello everybody! First congratulations on this forum! He has helped me a lot with phaserJs. I work with developing educational materials to Moodle and am trying to use the phaser in my applications. I would like to know how to write in a specific canvas element using the PhaserJS. That is, I can write in a predefined Canvas element?

Link to comment
Share on other sites

I really did not want to use the Canvas ... but in Moodle, which is the environment we work here, provides only a html editor field, when I call the phaser in this environment, it appears within the page and not the specific html space ... Since the Canvas, moodle easily recognize. Thanks for the reply.

Link to comment
Share on other sites



When you use Phaser.Game to create your game, you can pass a pre-existing canvas element in the arguments:

Game(width, height, renderer, parent, state, transparent, antialias, physicsConfig)

Where "parent" should be the id of your canvas.


More details here: http://docs.phaser.io/Phaser.Game.html

Hope that was what you were looking for!

Link to comment
Share on other sites

I don't understand what's wrong by Phaser creating a custom canvas for you. You call Phaser.Game giving it a dom element id, and it places the canvas there.


So you add this to your html

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

and call Phaser.Game

new Phaser.Game(640, 480, Phaser.AUTO, 'game-area');

This will create a canvas within the '#game-area'


So are you saying this is not possible using moodle, If not explain your problem more please.

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...