Be a Supporter!

AS: Black and White

  • 4,461 Views
  • 24 Replies
New Topic Respond to this Topic
fwe
fwe
  • Member since: Jul. 24, 2003
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
AS: Black and White 2005-12-10 13:42:41 Reply

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

Neashir
Neashir
  • Member since: Aug. 8, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to AS: Black and White 2005-12-10 13:44:08 Reply

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

fwe
fwe
  • Member since: Jul. 24, 2003
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Black and White 2005-12-10 13:45:56 Reply

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

liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS: Black and White 2005-12-10 13:46:21 Reply

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
T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to AS: Black and White 2005-12-10 13:47:37 Reply

omg lags like shit with b&w on.

not bad though.

glomph
glomph
  • Member since: Jun. 16, 2005
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to AS: Black and White 2005-12-10 13:47:59 Reply

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


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

BBS Signature
Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS: Black and White 2005-12-10 13:49:21 Reply

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

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


BBS Signature
glomph
glomph
  • Member since: Jun. 16, 2005
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to AS: Black and White 2005-12-10 13:50:02 Reply

nice* tut


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

BBS Signature
fwe
fwe
  • Member since: Jul. 24, 2003
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Black and White 2005-12-10 13:50:30 Reply

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

Madferit
Madferit
  • Member since: Jul. 29, 2005
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to AS: Black and White 2005-12-10 13:52:48 Reply

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

Awesome Job!

liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS: Black and White 2005-12-10 13:55:02 Reply

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
Gabe
Gabe
  • Member since: Feb. 28, 2003
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS: Black and White 2005-12-10 14:15:19 Reply

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

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS: Black and White 2005-12-10 14:16:35 Reply

laggy as hell but cool


- Matt, Rustyarcade.com

Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS: Black and White 2005-12-10 14:16:57 Reply

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
fwe
fwe
  • Member since: Jul. 24, 2003
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Black and White 2005-12-10 14:38:22 Reply

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

Just call me fwe


wtfbbqhax

GuyWithHisComp
GuyWithHisComp
  • Member since: Nov. 10, 2005
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to AS: Black and White 2005-12-11 03:27:38 Reply

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


BBS Signature
fwe
fwe
  • Member since: Jul. 24, 2003
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Black and White 2005-12-12 21:00:35 Reply

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

raitendo
raitendo
  • Member since: Feb. 19, 2001
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to AS: Black and White 2005-12-27 00:33:02 Reply

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.

fwe
fwe
  • Member since: Jul. 24, 2003
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Black and White 2005-12-27 01:07:23 Reply

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

SpaceAndTime
SpaceAndTime
  • Member since: May. 26, 2005
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Black and White 2005-12-27 01:22:11 Reply

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)

BrknPhoenix
BrknPhoenix
  • Member since: Dec. 1, 2005
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to AS: Black and White 2005-12-27 01:23:56 Reply

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

GeoKureli
GeoKureli
  • Member since: Apr. 1, 2003
  • Offline.
Forum Stats
Supporter
Level 19
Game Developer
Response to AS: Black and White 2005-12-27 01:27:48 Reply

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.

GeoKureli
GeoKureli
  • Member since: Apr. 1, 2003
  • Offline.
Forum Stats
Supporter
Level 19
Game Developer
Response to AS: Black and White 2005-12-27 01:43:16 Reply

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

worship me, WORSHIP ME

funnly

fully

attention whore
wyslet
wyslet
  • Member since: Apr. 1, 2007
  • Offline.
Forum Stats
Member
Level 09
Game Developer
Response to AS: Black and White 2007-07-08 17:41:34 Reply

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

Bobby444
Bobby444
  • Member since: Dec. 3, 2007
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to AS: Black and White 2008-01-28 15:51:22 Reply

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