From ba6863bdf557114d549a5f5f2b0f261f041cac72 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Sun, 17 Nov 2013 00:55:28 +0000 Subject: [PATCH] bmd tweaks --- examples/wip/bmd2.js | 13 +++++++---- src/gameobjects/BitmapData.js | 34 +++++++++++++++++++++++----- src/gameobjects/GameObjectFactory.js | 6 +++-- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/examples/wip/bmd2.js b/examples/wip/bmd2.js index 9f7d6a45..c973a226 100644 --- a/examples/wip/bmd2.js +++ b/examples/wip/bmd2.js @@ -21,7 +21,7 @@ function create() { // And apply it to 100 randomly positioned sprites for (var i = 0; i < 100; i++) { - bmd.setPixel(game.world.randomX, game.world.randomY, Math.random() * 255, Math.random() * 255, 255); + //bmd.setPixel(game.world.randomX, game.world.randomY, 100 + Math.random() * 155, 100 + Math.random() * 155, 255); } bmd.context.fillStyle = '#ffffff'; @@ -33,15 +33,20 @@ function create() { function update() { - // bmd.clear(); + // bmd.context.fillRect(game.world.randomX,game.world.randomY,4,4); - // updateWobblyBall(); + //console.log('b'); + + + // bmd.setPixel(game.world.randomX, game.world.randomY, 250, 250, 250); + + bmd.setPixel(game.input.x, game.input.y, 255, 255, 255); } function render() { - // bmd.render(); + bmd.render(); } diff --git a/src/gameobjects/BitmapData.js b/src/gameobjects/BitmapData.js index 04f741ad..d796dd08 100644 --- a/src/gameobjects/BitmapData.js +++ b/src/gameobjects/BitmapData.js @@ -25,6 +25,17 @@ Phaser.BitmapData = function (game, key, width, height) { */ this.game = game; + /** + * @property {boolean} exists - If exists = false then the BitmapData isn't updated by the core game loop. + * @default + */ + this.exists = true; + + /** + * @property {Phaser.Group} group - The parent Group of this BitmapData. + */ + this.group = null; + /** * @property {string} name - The name of the BitmapData. */ @@ -120,6 +131,8 @@ Phaser.BitmapData = function (game, key, width, height) { */ this.globalCompositeOperation = null; + this._dirty = false; + } Phaser.BitmapData.prototype = { @@ -127,6 +140,8 @@ Phaser.BitmapData.prototype = { clear: function () { this.context.clearRect(0, 0, this.width, this.height); + + this._dirty = true; }, @@ -157,6 +172,8 @@ Phaser.BitmapData.prototype = { this.imageData.data.set(this.data8); this.context.putImageData(this.imageData, 0, 0); + + this._dirty = true; } }, @@ -229,13 +246,18 @@ Phaser.BitmapData.prototype = { }, - render: function () { + postUpdate: function () { - // Only needed if running in WebGL, otherwise this array will never get cleared down I don't think! - if (this.game.renderType == Phaser.WEBGL) - { - PIXI.texturesToUpdate.push(this.baseTexture); - } + if (this._dirty) + { + // Only needed if running in WebGL, otherwise this array will never get cleared down I don't think! + if (this.game.renderType == Phaser.WEBGL) + { + PIXI.texturesToUpdate.push(this.baseTexture); + } + + this._dirty = false; + } } diff --git a/src/gameobjects/GameObjectFactory.js b/src/gameobjects/GameObjectFactory.js index c753018f..18f187e7 100644 --- a/src/gameobjects/GameObjectFactory.js +++ b/src/gameobjects/GameObjectFactory.js @@ -287,9 +287,11 @@ Phaser.GameObjectFactory.prototype = { */ bitmapData: function (key, width, height) { - var bmd = new Phaser.BitmapData(this.game, key, width, height); + // var bmd = new Phaser.BitmapData(this.game, key, width, height); - return this.game.cache.addBitmapData(bmd.name, bmd); + // return this.game.cache.addBitmapData(bmd.name, bmd); + + return this.world.add(new Phaser.BitmapData(this.game, x, y, width, height, tileset, tilemap, layer)); }