00:00
00:00
Newgrounds Background Image Theme

bugblast just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS: Black and White

5,849 Views | 22 Replies
New Topic Respond to this Topic

AS: Black and White 2005-12-10 13:42:41


AS: MAIN

AS: Black and White

I've seen a few people asking how to do this with the new flash 8, so I thought i'd post a solution. It converts your movie/game's color matrix filters so it has no saturation, which ultima5tely means it's black and white.

NOTE: It can and WILL lag your movie/game, but not so much. But enough to make a difference

I'm sure the code could be cleaned up more than it is, and I don't care about that. Don't turn this into some kind of contest to see how can shorten it the most.

function blackAndWhite(clear) {
lastBW.bm.dispose();
lastBW.mc.removeMovieClip();
if(clear) return
var mc = createEmptyMovieClip("bw"+getNextHighestDe
pth(), getNextHighestDepth());
var bm = new flash.display.BitmapData(Stage.width, Stage.height);
mc.attachBitmap(bm, 0);
bm.draw(_root);
BWMATRIX = [.3086,.6094,.082,0,0,.3086,.6094,.082,0,0
,.3086,.6094,.082,0,0,0,0,0,1,0];
var cm = new flash.filters.ColorMatrixFilter(BWMATRIX);
bm.applyFilter(bm, bm.rectangle, new Point(0, 0), cm);
lastBW = {mc:mc, bm:bm};
}

The first few lines and last line save the last movieclips and bitmapdatas made and removes them next frame, so it doesn't waste memory.

NOTE: To turn OFF black and white, you need to call it with true as an argument.

To turn black and white, keep calling it every frame.

EXAMPLES:

Discontinued christmas project

Discontinued fallout remake

Click the mouse on both of the examples to switch between color and B&W


wtfbbqhax

Response to AS: Black and White 2005-12-10 13:44:08


I don't have Flash 8, wish I did, but nice tutorial :D

Response to AS: Black and White 2005-12-10 13:45:56


At 12/10/05 01:44 PM, Christmas-Neashir wrote: I don't have Flash 8, wish I did, but nice tutorial :D

Thanks. You have the player 8, right? You should be able to see it.

Another thing,

var mc = createEmptyMovieClip("bw"+getNextHighestDe
pth(), getNextHighestDepth());

BWMATRIX = [.3086,.6094,.082,0,0,.3086,.6094,.082,0,0
,.3086,.6094,.082,0,0,0,0,0,1,0];

Those four lines are supposed to be two


wtfbbqhax

Response to AS: Black and White 2005-12-10 13:46:21


At 12/10/05 01:42 PM, fwe wrote: Black and White

Nice, I didn't notice much lag on the christmas game but the second game lagged a lot.

Yeah - cool tutorial.


Sup, bitches :)

BBS Signature

Response to AS: Black and White 2005-12-10 13:47:37


omg lags like shit with b&w on.

not bad though.

Response to AS: Black and White 2005-12-10 13:47:59


why did you discontinue them? there good.
o and inc tut


I have done the deed. Didst thou not hear a noise?

BBS Signature

Response to AS: Black and White 2005-12-10 13:49:21


At 12/10/05 01:45 PM, fwe wrote: Discontinued fallout remake

Who's Ighor? It's supposed to be Inglor! >:(


BBS Signature

Response to AS: Black and White 2005-12-10 13:50:02


nice* tut


I have done the deed. Didst thou not hear a noise?

BBS Signature

Response to AS: Black and White 2005-12-10 13:50:30


At 12/10/05 01:49 PM, -Toast- wrote:
At 12/10/05 01:45 PM, fwe wrote: Discontinued fallout remake
Who's Ighor? It's supposed to be Inglor! >:(

That's my name!

Russian family, i swear they were drunk when they named me

wtfbbqhax

Response to AS: Black and White 2005-12-10 13:52:48


At 12/10/05 01:45 PM, fwe wrote: cool stuff

Awesome Job!

Response to AS: Black and White 2005-12-10 13:55:02


At 12/10/05 01:50 PM, fwe wrote: That's my name!
Russian family, i swear they were drunk when they named me

What a nice name it is, too.

AS: Black and White


Sup, bitches :)

BBS Signature

Response to AS: Black and White 2005-12-10 14:16:35


laggy as hell but cool


- Matt, Rustyarcade.com

Response to AS: Black and White 2005-12-10 14:16:57


At 12/10/05 01:55 PM, -Christmas- wrote:
At 12/10/05 01:50 PM, fwe wrote: That's my name!
Russian family, i swear they were drunk when they named me
What a nice name it is, too.

Yes, it's true that it's a cool name. I would buy it for a dozen of dollars.

I_g_or || Inglor || Ighor. Funny, eh? :D

Anyway, very nice effect, Ighor ;)


BBS Signature

Response to AS: Black and White 2005-12-10 14:38:22


At 12/10/05 02:16 PM, -Toast- wrote: Anyway, very nice effect, Ighor ;)

Just call me fwe


wtfbbqhax

Response to AS: Black and White 2005-12-11 03:27:38


Nice script but it doesn't really explain the code.
Maybe Foss material?


BBS Signature

Response to AS: Black and White 2005-12-12 21:00:35


At 12/11/05 03:27 AM, GuyWithHisComp wrote: Nice script but it doesn't really explain the code.
Maybe Foss material?

Too late now


wtfbbqhax

Response to AS: Black and White 2005-12-27 00:33:02


Excuse me if I'm saying something stupid now, I know nothing about actionscripting filters

But...

I might be mistaken, but when I make my game black and white manually in Flash, ie without actionscript, I didn't notice any lag. Now, I haven't been able to get this code to work to compare it (I don't know how to use/where to put functions), but...

Do you have to create a bitmap overlay (if that's what the code is doing)? Can't you just change the _root colorMatrixFilter property or whatever? Again, I have no idea if this is possible as I know nothing about coding with filters, but just a thought.

Response to AS: Black and White 2005-12-27 01:07:23


At 12/27/05 12:33 AM, superbrightfuture wrote: Excuse me if I'm saying something stupid now, I know nothing about actionscripting filters

But...

I might be mistaken, but when I make my game black and white manually in Flash, ie without actionscript, I didn't notice any lag. Now, I haven't been able to get this code to work to compare it (I don't know how to use/where to put functions), but...

Do you have to create a bitmap overlay (if that's what the code is doing)? Can't you just change the _root colorMatrixFilter property or whatever? Again, I have no idea if this is possible as I know nothing about coding with filters, but just a thought.

I do the bitmap overlay solution. I'm not sure if you can make a ColorMatrixFilter on the root, I am probably mistaken, but I think it needs to be on a bitmapData object.


wtfbbqhax

Response to AS: Black and White 2005-12-27 01:23:56


...that's cool, but totally not worth it :p

Response to AS: Black and White 2005-12-27 01:27:48


import flash.filters.ColorMatrixFilter;
MovieClip.prototype.blackAndWhite = function(clear) {
myFilters = this.filters;
if (!clear) {
BWMatrix = [.3086, .6094, .082, 0, 0, .3086, .6094, .082, 0, 0, .3086, .6094, .082, 0, 0, 0, 0, 0, 1, 0];
this.BWFilterSpot == undefined ? this.BWFilterSpot = myFilters.length : null;
myFilters[this.BWFilterSpot] = new ColorMatrixFilter(BWMatrix);
} else {
myFilters[this.BWFilterSpot] = undefined;
}
this.filters = myFilters;
};
blackAndWhite(false);
i just took out the bitmap. its a huge hassle. i still dont funnly understand this filter so all credit still goes to fwe... my bestest fwend.

Response to AS: Black and White 2005-12-27 01:43:16


At 12/27/05 01:27 AM, ImpotentBoy2 wrote: code

worship me, WORSHIP ME

funnly

fully

attention whore

Response to AS: Black and White 2007-07-08 17:41:34


lol...stupid AS:main link...you suck...lol

Response to AS: Black and White 2008-01-28 15:51:22


Pretty nice but I don't really see why you would need black and white. Just make verything black and white in the first place. Also, if you are like me, you make your games with movie clips and buttons only and they can all have the saturation taken away without lag.


OMG FISH

BBS Signature