pyre Posted November 13, 2015 Share Posted November 13, 2015 Hey guys, I'm wondering if there's a faster way to set pixels on an image. This seems to work OK but rendering is something that I'd really like to speed up if possible.Also, if I eventually only set pixels that changed, maybe I shouldn't be using putImageData to copy all pixels each frame?Any ideas or advice are welcome. for (var x = 0; x < this.map.width; x++) { for (var y = 0; y < this.map.height; y++) { var cell = this.map.cells[x][y]; var a = 255; var r = cell.r; var g = cell.g; var b = cell.b; this.bmd.setPixel32(x,y, r, g, b, a, immediate=false); } } this.bmd.context.putImageData(this.bmd.imageData, 0, 0);Thanks very much,pyre Link to comment Share on other sites More sharing options...
jmp909 Posted November 13, 2015 Share Posted November 13, 2015 If your bmd is added as the texture of a Sprite , it should update itself, no need to manually redraw everything. (Might need to set .dirty=true)And yes , I assume your map doesn't change that often. , so only update parts of the texture as needed Link to comment Share on other sites More sharing options...
pyre Posted November 14, 2015 Author Share Posted November 14, 2015 If your bmd is added as the texture of a Sprite , it should update itself, no need to manually redraw everything. (Might need to set .dirty=true) Thanks for the reply. I tried with both an image and a sprite - the dirty flag doesn't cause a redraw at all.this.bmd.dirty = true; //placed instead of this.bmd.context.putImageData(this.bmd.imageData, 0, 0);And yes , I assume your map doesn't change that often. , so only update parts of the texture as neededPotentially a large portion could change in some frames, others little. So I need something that best suits both. - I guess by only updating those parts is just done automatically by only using setPixel32 on the pixels that changed, and phaser will handle the rest? Thanks again Link to comment Share on other sites More sharing options...
jmp909 Posted November 14, 2015 Share Posted November 14, 2015 hmm your method seems to be the way to do it and it's not fast http://phaser.io/sandbox/xJwnjIqn/play this is worth a look though. maybe copyRect is faster. i wonder if you could copyRect from a colour palette texture with 1x1 colours on ithttp://phaser.io/examples/v2/bitmapdata/wobble -- edit: no that's slower ...context.drawImage: http://phaser.io/sandbox/Wbkstglt/play also look at these rect: http://phaser.io/sandbox/rmiJgxCD/play processPixelRGB: http://phaser.io/sandbox/GOmiEhpp/play Link to comment Share on other sites More sharing options...
Recommended Posts