Skip to content

Commit ba6863b

Browse files
committed
bmd tweaks
1 parent 38bd00b commit ba6863b

3 files changed

Lines changed: 41 additions & 12 deletions

File tree

examples/wip/bmd2.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function create() {
2121
// And apply it to 100 randomly positioned sprites
2222
for (var i = 0; i < 100; i++)
2323
{
24-
bmd.setPixel(game.world.randomX, game.world.randomY, Math.random() * 255, Math.random() * 255, 255);
24+
//bmd.setPixel(game.world.randomX, game.world.randomY, 100 + Math.random() * 155, 100 + Math.random() * 155, 255);
2525
}
2626

2727
bmd.context.fillStyle = '#ffffff';
@@ -33,15 +33,20 @@ function create() {
3333

3434
function update() {
3535

36-
// bmd.clear();
36+
// bmd.context.fillRect(game.world.randomX,game.world.randomY,4,4);
3737

38-
// updateWobblyBall();
38+
//console.log('b');
39+
40+
41+
// bmd.setPixel(game.world.randomX, game.world.randomY, 250, 250, 250);
42+
43+
bmd.setPixel(game.input.x, game.input.y, 255, 255, 255);
3944

4045
}
4146

4247

4348
function render() {
4449

45-
// bmd.render();
50+
bmd.render();
4651

4752
}

src/gameobjects/BitmapData.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ Phaser.BitmapData = function (game, key, width, height) {
2525
*/
2626
this.game = game;
2727

28+
/**
29+
* @property {boolean} exists - If exists = false then the BitmapData isn't updated by the core game loop.
30+
* @default
31+
*/
32+
this.exists = true;
33+
34+
/**
35+
* @property {Phaser.Group} group - The parent Group of this BitmapData.
36+
*/
37+
this.group = null;
38+
2839
/**
2940
* @property {string} name - The name of the BitmapData.
3041
*/
@@ -120,13 +131,17 @@ Phaser.BitmapData = function (game, key, width, height) {
120131
*/
121132
this.globalCompositeOperation = null;
122133

134+
this._dirty = false;
135+
123136
}
124137

125138
Phaser.BitmapData.prototype = {
126139

127140
clear: function () {
128141

129142
this.context.clearRect(0, 0, this.width, this.height);
143+
144+
this._dirty = true;
130145

131146
},
132147

@@ -157,6 +172,8 @@ Phaser.BitmapData.prototype = {
157172
this.imageData.data.set(this.data8);
158173

159174
this.context.putImageData(this.imageData, 0, 0);
175+
176+
this._dirty = true;
160177
}
161178

162179
},
@@ -229,13 +246,18 @@ Phaser.BitmapData.prototype = {
229246

230247
},
231248

232-
render: function () {
249+
postUpdate: function () {
250+
251+
if (this._dirty)
252+
{
253+
// Only needed if running in WebGL, otherwise this array will never get cleared down I don't think!
254+
if (this.game.renderType == Phaser.WEBGL)
255+
{
256+
PIXI.texturesToUpdate.push(this.baseTexture);
257+
}
233258

234-
// Only needed if running in WebGL, otherwise this array will never get cleared down I don't think!
235-
if (this.game.renderType == Phaser.WEBGL)
236-
{
237-
PIXI.texturesToUpdate.push(this.baseTexture);
238-
}
259+
this._dirty = false;
260+
}
239261

240262
}
241263

src/gameobjects/GameObjectFactory.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,11 @@ Phaser.GameObjectFactory.prototype = {
287287
*/
288288
bitmapData: function (key, width, height) {
289289

290-
var bmd = new Phaser.BitmapData(this.game, key, width, height);
290+
// var bmd = new Phaser.BitmapData(this.game, key, width, height);
291291

292-
return this.game.cache.addBitmapData(bmd.name, bmd);
292+
// return this.game.cache.addBitmapData(bmd.name, bmd);
293+
294+
return this.world.add(new Phaser.BitmapData(this.game, x, y, width, height, tileset, tilemap, layer));
293295

294296
}
295297

0 commit comments

Comments
 (0)