Skip to content

Commit 5221bfd

Browse files
committed
You can now pass in your own Canvas element to Phaser and it will use that instead of creating one itself. To do so you must pass a Game Configuration object to Phaser when you instantiate it, and set the canvas property of the config object to be the DOM element you wish to use, i.e.: { canvas: document.getElementById('yourCanvas') } (thanks @Friksel phaserjs#2311)
1 parent 48ff74b commit 5221bfd

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
383383
* The Physics Manager will now throw a console warning if you try to enable a physics body using an unknown physics engine type (thanks @jakewilson #2415)
384384
* The Tileset class will tell you the name of the tileset image throwing the uneven size error (thanks @jakewilson #2415)
385385
* Emitter.start when used with a false `explode` parameter would cumulatively add particles to the current total. With quantity 10 the first call would emit 10 particles, the next 20, and so on. Calls to start will now reset the quantity each time. This is a behavior change from earlier versions, so if you relied on the old way please account for it in your code (thanks @BdR76 #2187)
386+
* You can now pass in your own Canvas element to Phaser and it will use that instead of creating one itself. To do so you must pass a Game Configuration object to Phaser when you instantiate it, and set the `canvas` property of the config object to be the DOM element you wish to use, i.e.: `{ canvas: document.getElementById('yourCanvas') }` (thanks @Friksel #2311)
386387

387388
### Bug Fixes
388389

src/core/Game.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,14 @@ Phaser.Game.prototype = {
681681
*/
682682
setUpRenderer: function () {
683683

684-
this.canvas = Phaser.Canvas.create(this, this.width, this.height, this.config['canvasID'], true);
684+
if (this.config['canvas'])
685+
{
686+
this.canvas = this.config['canvas'];
687+
}
688+
else
689+
{
690+
this.canvas = Phaser.Canvas.create(this, this.width, this.height, this.config['canvasID'], true);
691+
}
685692

686693
if (this.config['canvasStyle'])
687694
{

0 commit comments

Comments
 (0)