Forum Topic: AS: Black and White

(3,626 views • 24 replies)

This topic is 1 page long.

<< < > >>
None

fwe

Reply To Post Reply & Quote

Posted at: 12/10/05 01:42 PM

fwe DARK LEVEL 08

Sign-Up: 07/24/03

Posts: 3,361

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


None

Neashir

Reply To Post Reply & Quote

Posted at: 12/10/05 01:44 PM

Neashir NEUTRAL LEVEL 18

Sign-Up: 08/08/05

Posts: 1,401

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


None

fwe

Reply To Post Reply & Quote

Posted at: 12/10/05 01:45 PM

fwe DARK LEVEL 08

Sign-Up: 07/24/03

Posts: 3,361

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


None

liaaaam

Reply To Post Reply & Quote

Posted at: 12/10/05 01:46 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,541

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.


None

T-H

Reply To Post Reply & Quote

Posted at: 12/10/05 01:47 PM

T-H LIGHT LEVEL 39

Sign-Up: 01/07/04

Posts: 4,893

omg lags like shit with b&w on.

not bad though.


None

glomph

Reply To Post Reply & Quote

Posted at: 12/10/05 01:47 PM

glomph NEUTRAL LEVEL 10

Sign-Up: 06/16/05

Posts: 229

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

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

BBS Signature

None

Toast

Reply To Post Reply & Quote

Posted at: 12/10/05 01:49 PM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,924

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

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


None

glomph

Reply To Post Reply & Quote

Posted at: 12/10/05 01:50 PM

glomph NEUTRAL LEVEL 10

Sign-Up: 06/16/05

Posts: 229

nice* tut

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

BBS Signature

None

fwe

Reply To Post Reply & Quote

Posted at: 12/10/05 01:50 PM

fwe DARK LEVEL 08

Sign-Up: 07/24/03

Posts: 3,361

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


None

Madferit

Reply To Post Reply & Quote

Posted at: 12/10/05 01:52 PM

Madferit FAB LEVEL 10

Sign-Up: 07/29/05

Posts: 3,332

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

Awesome Job!


None

liaaaam

Reply To Post Reply & Quote

Posted at: 12/10/05 01:55 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,541

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


None

Gabe

Reply To Post Reply & Quote

Posted at: 12/10/05 02:15 PM

Gabe EVIL LEVEL 20

Sign-Up: 02/28/03

Posts: 570

Heh, that's a pretty nice tut you got there. It'd be awesome for switching between B/W and color Kill Bill style ;P


None

Rustygames

Reply To Post Reply & Quote

Posted at: 12/10/05 02:16 PM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,661

laggy as hell but cool

- Matt, Rustyarcade.com


None

Toast

Reply To Post Reply & Quote

Posted at: 12/10/05 02:16 PM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,924

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 ;)


None

fwe

Reply To Post Reply & Quote

Posted at: 12/10/05 02:38 PM

fwe DARK LEVEL 08

Sign-Up: 07/24/03

Posts: 3,361

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

Just call me fwe

wtfbbqhax


None

GuyWithHisComp

Reply To Post Reply & Quote

Posted at: 12/11/05 03:27 AM

GuyWithHisComp LIGHT LEVEL 27

Sign-Up: 11/10/05

Posts: 4,008

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

BBS Signature

None

fwe

Reply To Post Reply & Quote

Posted at: 12/12/05 09:00 PM

fwe DARK LEVEL 08

Sign-Up: 07/24/03

Posts: 3,361

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


None

raitendo

Reply To Post Reply & Quote

Posted at: 12/27/05 12:33 AM

raitendo NEUTRAL LEVEL 23

Sign-Up: 02/19/01

Posts: 443

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.


None

fwe

Reply To Post Reply & Quote

Posted at: 12/27/05 01:07 AM

fwe DARK LEVEL 08

Sign-Up: 07/24/03

Posts: 3,361

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


None

SpaceAndTime

Reply To Post Reply & Quote

Posted at: 12/27/05 01:22 AM

SpaceAndTime NEUTRAL LEVEL 07

Sign-Up: 05/26/05

Posts: 1,355

Hey, that's pretty awesome.
Would it be possible to do... I think it's called sepia? Instead of black and white it would be, for example, black and red. Could you do that? (I know nothing about actionscript)


None

BrknPhoenix

Reply To Post Reply & Quote

Posted at: 12/27/05 01:23 AM

BrknPhoenix EVIL LEVEL 06

Sign-Up: 12/01/05

Posts: 120

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


None

ImpotentBoy2

Reply To Post Reply & Quote

Posted at: 12/27/05 01:27 AM

ImpotentBoy2 LIGHT LEVEL 18

Sign-Up: 04/01/03

Posts: 5,318

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.

Some times my "L" key decides not to work.


None

ImpotentBoy2

Reply To Post Reply & Quote

Posted at: 12/27/05 01:43 AM

ImpotentBoy2 LIGHT LEVEL 18

Sign-Up: 04/01/03

Posts: 5,318

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

worship me, WORSHIP ME

funnly

fully

attention whore

Some times my "L" key decides not to work.


None

wyslet

Reply To Post Reply & Quote

Posted at: 7/8/07 05:41 PM

wyslet LIGHT LEVEL 09

Sign-Up: 04/01/07

Posts: 169

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


None

Bobby444

Reply To Post Reply & Quote

Posted at: 1/28/08 03:51 PM

Bobby444 DARK LEVEL 05

Sign-Up: 12/03/07

Posts: 848

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

All times are Eastern Standard Time (GMT -5) | Current Time: 08:54 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!