Skip to content

Commit 418a161

Browse files
committed
Testing webgl debug overlay.
1 parent 442e6bb commit 418a161

4 files changed

Lines changed: 91 additions & 5 deletions

File tree

examples/wip/debug.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
3+
4+
var tilesprite;
5+
var cursors;
6+
var count = 0;
7+
8+
function preload() {
9+
10+
game.load.image('starfield', 'assets/misc/starfield.jpg');
11+
game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
12+
game.load.atlas('seacreatures', 'assets/sprites/seacreatures_json.png', 'assets/sprites/seacreatures_json.json');
13+
14+
}
15+
16+
var sprite;
17+
18+
function create() {
19+
20+
sprite = game.add.tileSprite(0, 0, 800, 600, 'starfield');
21+
sprite.autoScroll(0, 200);
22+
23+
game.add.image(200, 200, 'mummy');
24+
25+
game.world.scale.set(2);
26+
27+
}
28+
29+
function update() {
30+
31+
}
32+
33+
function render() {
34+
35+
game.debug.renderText(sprite.frame, 32, 32);
36+
37+
}

src/gameobjects/BitmapData.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ Phaser.BitmapData.prototype = {
152152

153153
if (width !== this.width || height !== this.height)
154154
{
155-
console.log('bmd resize', width, height);
156155
this.width = width;
157156
this.height = height;
158157
this.canvas.width = width;
@@ -367,7 +366,8 @@ Phaser.BitmapData.prototype = {
367366
// Only needed if running in WebGL, otherwise this array will never get cleared down
368367
if (this.game.renderType === Phaser.WEBGL)
369368
{
370-
PIXI.texturesToUpdate.push(this.baseTexture);
369+
// should use the rendersession
370+
PIXI.updateWebGLTexture(this.baseTexture, this.game.renderer.gl);
371371
}
372372

373373
this._dirty = false;

src/tilemap/TilemapLayer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,6 @@ Phaser.TilemapLayer.prototype.render = function () {
666666
this.renderDebug();
667667
}
668668

669-
// Only needed if running in WebGL, otherwise this array will never get cleared down I don't think!
670669
if (this.game.renderType === Phaser.WEBGL)
671670
{
672671
// PIXI.updateWebGLTexture(this.baseTexture, renderSession.gl);

src/utils/Debug.js

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,34 @@ Phaser.Utils.Debug = function (game) {
2020
this.game = game;
2121

2222
/**
23-
* @property {Context} context - The canvas context on which to render the debug information.
23+
* @property {PIXI.Sprite} sprite - If debugging in WebGL mode we need this.
2424
*/
25-
this.context = game.context;
25+
this.sprite = null;
26+
27+
/**
28+
* @property {HTMLCanvasElement} canvas - The canvas to which this BitmapData draws.
29+
*/
30+
this.canvas = null;
31+
32+
/**
33+
* @property {PIXI.BaseTexture} baseTexture - Required Pixi var.
34+
*/
35+
this.baseTexture = null;
36+
37+
/**
38+
* @property {PIXI.Texture} texture - Required Pixi var.
39+
*/
40+
this.texture = null;
41+
42+
/**
43+
* @property {Phaser.Frame} textureFrame - Dimensions of the renderable area.
44+
*/
45+
this.textureFrame = null;
46+
47+
/**
48+
* @property {CanvasRenderingContext2D} context - The 2d context of the canvas.
49+
*/
50+
this.context = null;
2651

2752
/**
2853
* @property {string} font - The font that the debug information is rendered in.
@@ -63,6 +88,24 @@ Phaser.Utils.Debug = function (game) {
6388
*/
6489
this.currentAlpha = 1;
6590

91+
if (this.game.renderType === Phaser.CANVAS)
92+
{
93+
this.context = this.game.context;
94+
}
95+
else
96+
{
97+
this.canvas = Phaser.Canvas.create(this.game.width, this.game.height, '', true);
98+
this.context = this.canvas.getContext('2d');
99+
this.context.fillStyle = '#ff0000';
100+
this.context.fillRect(0,0,400,400);
101+
this.baseTexture = new PIXI.BaseTexture(this.canvas);
102+
this.texture = new PIXI.Texture(this.baseTexture);
103+
this.textureFrame = new Phaser.Frame(0, 0, 0, this.game.width, this.game.height, 'debug', game.rnd.uuid());
104+
this.sprite = this.game.make.image(0, 0, this.texture, this.textureFrame);
105+
106+
this.game.stage.addChild(this.sprite);
107+
}
108+
66109
};
67110

68111
Phaser.Utils.Debug.prototype = {
@@ -111,6 +154,13 @@ Phaser.Utils.Debug.prototype = {
111154
this.context.restore();
112155
this.context.globalAlpha = this.currentAlpha;
113156

157+
if (this.sprite)
158+
{
159+
this.context.fillStyle = '#ff0000';
160+
this.context.fillRect(0,0,400,400);
161+
PIXI.updateWebGLTexture(this.baseTexture, this.game.renderer.gl);
162+
}
163+
114164
},
115165

116166
/**

0 commit comments

Comments
 (0)