Skip to content

Commit

Permalink
Expanding BitmapData
Browse files Browse the repository at this point in the history
  • Loading branch information
photonstorm committed Nov 17, 2013
1 parent ba6863b commit 7ad4164
Show file tree
Hide file tree
Showing 7 changed files with 1,065 additions and 119 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Version 1.1.3 - in build
* New: Added Group.iterate, a powerful way to count or return children that match a certain criteria. Refactored Group to use iterate, lots of repeated code cut.
* New: Added Group.sort. You can now sort the Group based on any given numeric property (x, y, health), finally you can do depth-sorting :) Example created to show.
* New: Enhanced renderTexture so it can accept a Phaser.Group object and improved documentation and examples.

* Fixed: Lots of fixes to the TypeScript definitions file (many thanks gltovar)
* Fixed: Tilemap commands use specified layer when one given (thanks Izzimach)
* Fixed: Mouse.stop now uses the true useCapture, which means the event listeners stop listening correctly (thanks beeglebug)
Expand All @@ -65,14 +66,15 @@ Version 1.1.3 - in build
* Fixed: Group.swap had a hellish to find bug that only manifested when B-A upward swaps occured. Hours of debugging later = bug crushed.
* Fixed: Point.rotate asDegrees fixed (thanks BorisKozo)
* Fixed: ArcadePhysics.separateTile wasn't returning the value, so the custom process callback wasn't getting called (thanks flameiguana)

* Updated: ArcadePhysics.updateMotion applies the dt to the velocity calculations as well as position now (thanks jcs)
* Updated: RequestAnimationFrame now retains the callbackID which is passed to cancelRequestAnimationFrame.
* Updated: Button now goes back to over state when setFrames used in action (thanks beeglebug)
* Updated: plugins now have a postUpdate callback (thanks cocoademon)
* Updated: Tided up the Graphics object (thanks BorisKozo)
* Updated: If running in Canvas mode and you have a render function it will save the context and reset the transform before running your render function.
* Updated: Sprite will now check the exists property of the Group it is in, if the Group.exists = false the Sprite won't update.
* Updated: Lots of small documentation tweaks across various files such as Pointer.
* Updated: Lots of documentation tweaks across various files such as Pointer and Color.
* Updated: If you specify 'null' as a Group parent it will now revert to using the World as the parent (before only 'undefined' worked)


Expand Down
29 changes: 14 additions & 15 deletions examples/wip/bmd2.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,32 @@ var bmd;

function create() {

//game.stage.backgroundColor = '#450034';
bmd = game.add.bitmapData(800, 600);

bmd = game.add.bitmapData('bob', 800, 600);
console.log('isLittleEndian', bmd.isLittleEndian);
bmd.isLittleEndian = false;

bmd.beginPath();
bmd.beginLinearGradientFill(["#ff0000", "#ffff00"], [0, 1], 0, 0, 0, 600);
bmd.rect(0, 0, 800, 600);
bmd.closePath();
bmd.fill();

bmd.refreshBuffer();

// And apply it to 100 randomly positioned sprites
for (var i = 0; i < 100; i++)
{
//bmd.setPixel(game.world.randomX, game.world.randomY, 100 + Math.random() * 155, 100 + Math.random() * 155, 255);
bmd.setPixel(game.world.randomX, game.world.randomY, 0, 0, 0);
}

bmd.context.fillStyle = '#ffffff';
bmd.context.fillRect(20,20,16,16);

var d = game.add.sprite(0, 0, bmd);

}

function update() {

// bmd.context.fillRect(game.world.randomX,game.world.randomY,4,4);

//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);
bmd.refreshBuffer();
bmd.setPixel(game.input.x, game.input.y, 0, 0, 0);

}

Expand Down
74 changes: 74 additions & 0 deletions examples/wip/bmd3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });

function preload() {

game.load.image('atari1', 'assets/sprites/atari130xe.png');

}

var bmd;
var img;

function create() {

var canvas = Phaser.Canvas.create(800, 600);
var context = canvas.getContext('2d');

context.drawImage(game.cache.getImage('atari1'), 0, 0);

img = context.getImageData(0, 0, 800, 600);

var data8 = new Uint8ClampedArray(img.data.buffer);
var data32 = new Uint32Array(img.data.buffer);

context.drawImage(game.cache.getImage('atari1'), 32, 50);

img = context.getImageData(0, 0, 800, 600);

// console.log(data32[y * 800 + x]);

var alpha = 255;
var blue = 50;
var red = 50;
var green = 100;

for (var y = 0; y < 100; y++)
{
for (var x = 0; x < 250; x++)
{
// var value = x * y & 0xff;
// console.log(data32[y * 800 + x]);
// data32[((y + 100) * 800) + x] = 0;
// data32[y * 800 + x] = (alpha << 24) | (blue << 16) | (green << 8) | red;;
// data32[y * 800 + x] = (red << 24) | (green << 16) | (blue << 8) | alpha;
data32[y * 800 + (x + 300)] = data32[y * 800 + x];
}
}

// if (this.isLittleEndian)
// {
// this.data32[y * this.width + x] = (alpha << 24) | (blue << 16) | (green << 8) | red;
// }
// else
// {
// this.data32[y * this.width + x] = (red << 24) | (green << 16) | (blue << 8) | alpha;
// }

img.data.set(data8);
context.putImageData(img, 0, 0);

document.getElementById('phaser-example').appendChild(canvas);

}

function update() {


}


function render() {


}
Loading

0 comments on commit 7ad4164

Please sign in to comment.