Skip to content

Commit 86584a6

Browse files
committed
Added new Phaser.HEADLESS render mode (doesn't output anything).
1 parent 06a17b4 commit 86584a6

4 files changed

Lines changed: 45 additions & 17 deletions

File tree

build/phaser.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* Phaser - http://www.phaser.io
2020
*
21-
* v1.1.3 - Built at: Mon Nov 25 2013 13:10:47
21+
* v1.1.3 - Built at: Mon Nov 25 2013 14:14:28
2222
*
2323
* By Richard Davey http://www.photonstorm.com @photonstorm
2424
*
@@ -60,9 +60,11 @@ var Phaser = Phaser || {
6060
VERSION: '1.1.3',
6161
DEV_VERSION: '1.1.3',
6262
GAMES: [],
63+
6364
AUTO: 0,
6465
CANVAS: 1,
6566
WEBGL: 2,
67+
HEADLESS: 3,
6668

6769
SPRITE: 0,
6870
BUTTON: 1,
@@ -13660,7 +13662,7 @@ Object.defineProperty(Phaser.World.prototype, "visible", {
1366013662
* @constructor
1366113663
* @param {number} [width=800] - The width of your game in game pixels.
1366213664
* @param {number} [height=600] - The height of your game in game pixels.
13663-
* @param {number} [renderer=Phaser.AUTO] - Which renderer to use (canvas or webgl)
13665+
* @param {number} [renderer=Phaser.AUTO] - Which renderer to use: Phaser.AUTO will auto-detect, Phaser.WEBGL, Phaser.CANVAS or Phaser.HEADLESS (no rendering at all).
1366413666
* @param {HTMLElement} [parent=''] - The Games DOM parent.
1366513667
* @param {any} [state=null] - Description.
1366613668
* @param {boolean} [transparent=false] - Use a transparent canvas background or not.
@@ -13978,6 +13980,10 @@ Phaser.Game.prototype = {
1397813980
{
1397913981
r = 'WebGL';
1398013982
}
13983+
else if (this.renderType == Phaser.HEADLESS)
13984+
{
13985+
r = 'Headless';
13986+
}
1398113987

1398213988
if (this.device.webAudio)
1398313989
{
@@ -14012,11 +14018,15 @@ Phaser.Game.prototype = {
1401214018
*/
1401314019
setUpRenderer: function () {
1401414020

14015-
if (this.renderType === Phaser.CANVAS || (this.renderType === Phaser.AUTO && this.device.webGL === false))
14021+
if (this.renderType === Phaser.HEADLESS || this.renderType === Phaser.CANVAS || (this.renderType === Phaser.AUTO && this.device.webGL === false))
1401614022
{
1401714023
if (this.device.canvas)
1401814024
{
14019-
this.renderType = Phaser.CANVAS;
14025+
if (this.renderType === Phaser.AUTO)
14026+
{
14027+
this.renderType = Phaser.CANVAS;
14028+
}
14029+
1402014030
this.renderer = new PIXI.CanvasRenderer(this.width, this.height, this.stage.canvas, this.transparent);
1402114031
Phaser.Canvas.setSmoothingEnabled(this.renderer.context, this.antialias);
1402214032
this.canvas = this.renderer.view;
@@ -14089,11 +14099,15 @@ Phaser.Game.prototype = {
1408914099
this.world.postUpdate();
1409014100
this.plugins.postUpdate();
1409114101

14092-
this.renderer.render(this.stage._stage);
14093-
this.plugins.render();
14094-
this.state.render();
14102+
if (this.renderType !== Phaser.HEADLESS)
14103+
{
14104+
this.renderer.render(this.stage._stage);
14105+
this.plugins.render();
14106+
this.state.render();
14107+
14108+
this.plugins.postRender();
14109+
}
1409514110

14096-
this.plugins.postRender();
1409714111
}
1409814112

1409914113
},

build/phaser.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Phaser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ var Phaser = Phaser || {
1212
VERSION: '<%= version %>',
1313
DEV_VERSION: '1.1.3',
1414
GAMES: [],
15+
1516
AUTO: 0,
1617
CANVAS: 1,
1718
WEBGL: 2,
19+
HEADLESS: 3,
1820

1921
SPRITE: 0,
2022
BUTTON: 1,

src/core/Game.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @constructor
1717
* @param {number} [width=800] - The width of your game in game pixels.
1818
* @param {number} [height=600] - The height of your game in game pixels.
19-
* @param {number} [renderer=Phaser.AUTO] - Which renderer to use (canvas or webgl)
19+
* @param {number} [renderer=Phaser.AUTO] - Which renderer to use: Phaser.AUTO will auto-detect, Phaser.WEBGL, Phaser.CANVAS or Phaser.HEADLESS (no rendering at all).
2020
* @param {HTMLElement} [parent=''] - The Games DOM parent.
2121
* @param {any} [state=null] - Description.
2222
* @param {boolean} [transparent=false] - Use a transparent canvas background or not.
@@ -334,6 +334,10 @@ Phaser.Game.prototype = {
334334
{
335335
r = 'WebGL';
336336
}
337+
else if (this.renderType == Phaser.HEADLESS)
338+
{
339+
r = 'Headless';
340+
}
337341

338342
if (this.device.webAudio)
339343
{
@@ -368,11 +372,15 @@ Phaser.Game.prototype = {
368372
*/
369373
setUpRenderer: function () {
370374

371-
if (this.renderType === Phaser.CANVAS || (this.renderType === Phaser.AUTO && this.device.webGL === false))
375+
if (this.renderType === Phaser.HEADLESS || this.renderType === Phaser.CANVAS || (this.renderType === Phaser.AUTO && this.device.webGL === false))
372376
{
373377
if (this.device.canvas)
374378
{
375-
this.renderType = Phaser.CANVAS;
379+
if (this.renderType === Phaser.AUTO)
380+
{
381+
this.renderType = Phaser.CANVAS;
382+
}
383+
376384
this.renderer = new PIXI.CanvasRenderer(this.width, this.height, this.stage.canvas, this.transparent);
377385
Phaser.Canvas.setSmoothingEnabled(this.renderer.context, this.antialias);
378386
this.canvas = this.renderer.view;
@@ -445,11 +453,15 @@ Phaser.Game.prototype = {
445453
this.world.postUpdate();
446454
this.plugins.postUpdate();
447455

448-
this.renderer.render(this.stage._stage);
449-
this.plugins.render();
450-
this.state.render();
456+
if (this.renderType !== Phaser.HEADLESS)
457+
{
458+
this.renderer.render(this.stage._stage);
459+
this.plugins.render();
460+
this.state.render();
461+
462+
this.plugins.postRender();
463+
}
451464

452-
this.plugins.postRender();
453465
}
454466

455467
},

0 commit comments

Comments
 (0)