PDA

View Full Version : bitmapdata + colorTransform / blend mode / filter problem



scottc
October 16th, 2008, 03:33 AM
I'm making a worms / leiro type game..

And I'm trying to make the ground change color around the "explosions" so it looks like the ground is burnt.

this is what i have so far:


public function blastCircle(x:int,y:int,r:uint):void{
//make temp circle to cut hole
var c:Sprite = new Sprite();

c.graphics.beginFill(0x000000);
c.graphics.drawCircle(x, y, r+1);
c.graphics.endFill();
//make a black circle that only affects opaque pixels
draw(c, null, new ColorTransform(1,1,1,0.5,0,0,0,0));

c.graphics.clear();
c.graphics.beginFill(0xFFFFFF);
c.graphics.drawCircle(x, y, r);
c.graphics.endFill();
draw(c, null, null, "erase");

//resetPalette();

}

You can see what i've got so far (http://scottcampbell.com.au/flash/terrain_destruction_game_engine) (without the black ring code).

I cant seem to find the correct blend mode or color transformation etc to make it affect only opaque pixels. so i end up with the burnt area also affecting the "air".

scottc
October 16th, 2008, 07:09 AM
Update:

I tried to remove any semi-transperent pixels with threshold, but i seem to be doing it wrong lol.


this.threshold(this, new Rectangle(0,0,9999,9999),new Point(0,0), ">", 0xFF, 0x00, 0x00);

I can do it with paletteMap, however i'm not sure if it's faster then using threshold.


var aa:Array = new Array(256);
for(var i:uint = 0; i < 255; i++) {
aa[i] = 0x00000000;
}

aa[0xFF] = 0xFF000000;

this.paletteMap(this,new Rectangle(0,0,9999,9999),new Point(0,0),null,null,null,aa);

scottc
October 16th, 2008, 07:40 AM
I found a solution, but i don't think its the fastest..

And i found why, the threshold wasn't working, needed write out the colors in full..
0xFF000000, 0x00000000



public function blastCircle(x:int,y:int,r:uint):void{
//make temp circle to cut hole
var c:Sprite = new Sprite();

c.graphics.beginFill(0x000000, 0.5);
c.graphics.drawCircle(x, y, r+1);
c.graphics.endFill();

draw(c);

c.graphics.clear();
c.graphics.beginFill(0xFFFFFF);
c.graphics.drawCircle(x, y, r);
c.graphics.endFill();
draw(c, null, null, "erase");

resetPalette(x-r-1,y-r-1,(r+1)*2,(r+1)*2);

}

public function resetPalette(x:uint = 0,y:uint = 0,w:uint = 0,h:uint = 0):void{
//set the paletteMap to boolean transperency like a 8bit png or gif
/*
var aa:Array = new Array(256);
for(var i:uint = 0; i < 255; i++) {
aa[i] = 0x00000000;
}

aa[0xFF] = 0xFF000000;

this.paletteMap(this,new Rectangle(x,y,w,h),new Point(x,y),null,null,null,aa);
*/


this.threshold(this, new Rectangle(x,y,w,h),new Point(x,y), "<", 0xFF000000, 0x00000000);
}


Now i have to test threshold vs palettemap, and see what comes out top for performance..

at the moment I'm now using the threshold, and it seems to be running pretty smooth.
I think it could have better performance with something more simple, like a filter?

i'll update the one on my website (http://scottcampbell.com.au/flash/terrain_destruction_game_engine), so you can see the result.