Jump to content

Bitmapdata


charlie_says
 Share

Recommended Posts

Hi,

 

I'm sure I'm missing something very obvious, but, can anyone point out where I'm going wrong here:

shotBMD = game.add.bitmapData(8, 8);shotBMD.context.drawImage(game.cache.getImage('shot'), 0, 0, 8, 8);var col = shotBMD.getPixel32(3,3);// Uncaught TypeError: Cannot read property '27' of undefined 
Link to comment
Share on other sites

BitmapData.getPixel32 will give you an rgba color value (warning: endianess applies)

BitmapData.getPixel and BitmapData.getPixelRGB (which is what the example above uses) gives you a color object like you posted above.

 

The difference between the two is that getPixel works across the slower data array, but is really useful in some cases.

Link to comment
Share on other sites

I don't think I'm confused about how it should work, I think the returned data is incorrect.

 

this code:

bgBMD = game.add.bitmapData(350, 130);bgBMD.draw(game.cache.getImage('bg'), 0, 0);var col;col = bgBMD.getPixel32(1,1)console.log(col)col = bgBMD.getPixel32(10,10)console.log(colcol = bgBMD.getPixel32(100,100)console.log(col)col = bgBMD.getPixel32(150,100)console.log(col)col = bgBMD.getPixel(1,1)console.log(col)col = bgBMD.getPixel(10,10)console.log(col)col = bgBMD.getPixel(100,100)console.log(col)col = bgBMD.getPixel(150,100)console.log(col) 

 

returns this:

 

Object {r0g0b0a1h0…}play.js:62
Object {r0g0b0a1h0…}play.js:64
Object {r0g0b0a1h0…}play.js:66
Object {r0g0b0a1h0}

 

from this image:

bg.png

Link to comment
Share on other sites

With your image, and more importantly the following code, I get this:

var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });function preload() {    game.load.image('pic', 'assets/wip/bg.png');}var bmd;function create() {	bmd = game.make.bitmapData(800, 600);	bmd.draw('pic', 0, 0);	bmd.update();	game.add.sprite(0, 0, bmd);	var col;	col = bmd.getPixel32(1,1)	console.log(col)	col = bmd.getPixel32(10,10)	console.log(col)	col = bmd.getPixel32(100,100)	console.log(col)	col = bmd.getPixel32(150,100)	console.log(col)	col = bmd.getPixel(1,1)	console.log(col)	col = bmd.getPixel(10,10)	console.log(col)	col = bmd.getPixel(100,100)	console.log(col)	col = bmd.getPixel(150,100)	console.log(col) }
0042847647374284764737Object {r: 0, g: 0, b: 0, a: 1, h: 0…}Object {r: 0, g: 0, b: 0, a: 1, h: 0…}Object {r: 65, g: 82, b: 100, a: 255, h: 0…}Object {r: 65, g: 82, b: 100, a: 255, h: 0…}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...