00:00
00:00
Newgrounds Background Image Theme

Da-Birb 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!

Foss: Recording W/ Bitmapdata

1,559 Views | 14 Replies
New Topic Respond to this Topic

Foss: Recording W/ Bitmapdata 2005-10-28 16:10:53


FOSS: Recording w/ BitmapData
FOSS: Main

What we’re trying to do…
Is make a pseudo-recording of the stage, and play it back when you want it to stop recording. This can be done in various methods, the best way would be filling up an array with coordinates of each object.

NOTE: This shouldn’t be used for gaming, it’ll cause trouble
Think about it this way, each pixel requires 4 bits of ram for each channel (R,G,B,A). That sounds like nothing, but if the stage is 550x400 (default), that’s 550x400x4 bits, which is about 107kb. If you’re running this at 24 FPS and record 10 seconds, you’re wasting about 50 MB of RAM! Forgive my RAM conversion in the fla, I realize it’s wrong.

Code & Explanation

First and foremost, we have to import some important classes, BitmapData being the only one we’re actually going to use. The rest are for passing required arguments that need those classes.

import flash.display.BitmapData
import flash.geom.Rectangle;
import flash.geom.Matrix;
import flash.geom.ColorTransform;

I also import the filters.BlurFilter class to add some effect to our little square.

Here I have a little function that creates a movieclip, draws the stage, and stores it far away for us to playback later. Looping through all the pixels to get their values to store in an array would lag a lot, and take up the same amount of RAM.

createBitmap = function(){
var bmc = createEmptyMovieClip("Bm_Mc"+d(),d())
var bm = new BitmapData(w,h,true)
bmc.attachBitmap(bm,bmc.d())
bm.draw(_root, new Matrix(), new ColorTransform(), false, new Rectangle(0,0,w,h))
//Store far away
bmc._x = bmc._y = -1300
return bmc
}

Explanation… it creates a movieclip, creates a BitmapData that attaches to the MC, the BitmapData draws the stage, and it moves the movieclip away from the screen. You also notice I used d(), I just don’t feel like typing getNextHighestDepth() 20,000 times, and I sure as hell wasn’t going to stoop to making currentDepth++ or some shit like that, so I created a little function that you have to type 3 characters for.

Object.prototype.d = function() { return this.getNextHighestDepth() }

I also made some constant vars just for simplicity

w = Stage.width; h = Stage.height
Now, to record and playback. I made it so when you click the mouse, it starts recording and when you click again it plays back. You can change to keys or whatever the fuck suits you, I don’t care.

onMouseDown = function(){
recording = !recording
recording ? frames=[] : null
playback = !recording
playback?index=0:null
}

What that says:

Recording = (is recording false)
If recording, frames=[]
Playback = (is recording false)
If playback, index=0

Okay, now that we got that down, we need to say what happens when recording is true, or when playback is true. So…

Object.prototype.cleanup = function() { this.bm.dispose(); this.removeMovieClip() }
onEnterFrame = function() {
if(recording) frames.push(createBitmap())
if(playback){
prevmc.cleanup()
var len = frames.length
playback=index!=len
var mc = prevmc = frames[index]
mc._x = mc._y = 0
index++
}
}

If it’s recording, it pushes into the frame array, a movieclip with the drawing for that frame.
For playback, it first calls the function dispose, which removes the last MC it created, so it can free up that RAM we love. It gets the constant len(constant for the duration of that playback) and gets the movieclip from the array. It puts the movieclip in it’s origin, so it can show it fully, then ups the index for us to see the next frame when the time comes.

Source code & conclusion

Like I said, this is not a good method to make recording for games, it is just a little experiment I thought I’d share.

Source code: http://www.fweflash...lash/movieRecord.fla

Comments, questions, whatever, don’t hesitate (unless you’re NC, I won’t take your suggestions and won’t care for whatever little smart ass thing you have to say,) thanks.


wtfbbqhax

Response to Foss: Recording W/ Bitmapdata 2005-10-28 16:12:14


Awesome! Thanks for telling me about it on aim before you even posted :)


BBS Signature

Response to Foss: Recording W/ Bitmapdata 2005-10-28 16:21:53


I made something incredible similar to this 2/3 days after Flash 8 was released.. mine just records webcam, rather than anything else.

When you're using the draw function on the BitmapData, you don't need all that rectangle, colour transform, etc, bullshit.. just leave it out.

Heres mine.. coincidentally I was showing my mate this earlier :)

Also, heres a topic I made about it.


Sup, bitches :)

BBS Signature

Response to Foss: Recording W/ Bitmapdata 2005-10-28 16:28:19


At 10/28/05 04:21 PM, -liam- wrote: When you're using the draw function on the BitmapData, you don't need all that rectangle, colour transform, etc, bullshit.. just leave it out.

I just put it there to test clipping the recording so it doesnt always have to be fullscreen


wtfbbqhax

Response to Foss: Recording W/ Bitmapdata 2005-10-28 16:52:36


At 10/28/05 04:10 PM, fwe wrote:
NOTE: This shouldn’t be used for gaming, it’ll cause trouble
Think about it this way, each pixel requires 4 bits of ram for each channel (R,G,B,A). That sounds like nothing, but if the stage is 550x400 (default), that’s 550x400x4 bits, which is about 107kb. If you’re running this at 24 FPS and record 10 seconds, you’re wasting about 50 MB of RAM! Forgive my RAM conversion in the fla, I realize it’s wrong.

wrong

each pixel requires 32bits, 8 bits per channel, thats why its called 32bit ARGB and then you have 24bit RGB

Response to Foss: Recording W/ Bitmapdata 2005-10-28 16:55:22


At 10/28/05 04:52 PM, dELta_Luca wrote: each pixel requires 32bits, 8 bits per channel, thats why its called 32bit ARGB and then you have 24bit RGB

Can you translate please? =)


BBS Signature

Response to Foss: Recording W/ Bitmapdata 2005-10-28 16:56:23


At 10/28/05 04:52 PM, dELta_Luca wrote: each pixel requires 32bits, 8 bits per channel, thats why its called 32bit ARGB and then you have 24bit RGB

That makes so much more sense. Forgive me for sounding like an idiot


wtfbbqhax

Response to Foss: Recording W/ Bitmapdata 2005-10-28 16:59:51


At 10/28/05 04:55 PM, -Toast- wrote: Can you translate please? =)

For every pixel in a bitmap your computer uses 36 bytes of RAM. Every channel (alpha, red, green and blue (ARGB)) requires 8 bytes, their are 4 channels per pixel so 8*4 = 36.

Understand?


Sup, bitches :)

BBS Signature

Response to Foss: Recording W/ Bitmapdata 2005-10-28 17:02:09


At 10/28/05 04:59 PM, -liam- wrote: Understand?

Yes, much better.

So does it mean if you have an EXCELENT quality photo, you can just zoom in a lot until you see pixels and even inside the pixels you can see different colors?


BBS Signature

Response to Foss: Recording W/ Bitmapdata 2005-10-28 17:02:21


At 10/28/05 04:59 PM, -liam- wrote:
At 10/28/05 04:55 PM, -Toast- wrote: Can you translate please? =)
For every pixel in a bitmap your computer uses 36 bytes of RAM. Every channel (alpha, red, green and blue (ARGB)) requires 8 bytes, their are 4 channels per pixel so 8*4 = 36.

Understand?

It requires 8 bits, not bytes, and 8*4 is 32 :)


wtfbbqhax

Response to Foss: Recording W/ Bitmapdata 2005-10-28 17:04:34


At 10/28/05 05:02 PM, fwe wrote: , and 8*4 is 32 :)

Rofl at Liam's maths :D

So does it mean you can use 4 other bits for your game?

Lol, I'm confused.


BBS Signature

Response to Foss: Recording W/ Bitmapdata 2005-10-28 17:06:19


At 10/28/05 05:02 PM, fwe wrote: It requires 8 bits, not bytes, and 8*4 is 32 :)

I thought bits were bytes, and I misread.. heh, now I look stupid :)


Sup, bitches :)

BBS Signature

Response to Foss: Recording W/ Bitmapdata 2005-10-28 17:08:05


At 10/28/05 05:02 PM, -Toast- wrote: So does it mean if you have an EXCELENT quality photo, you can just zoom in a lot until you see pixels and even inside the pixels you can see different colors?

No, the ARGB value is the amount of each one in a pixel.. and it makes one whole colour.

argh, meant to copy and paste this.. second time I've done it today =P

Sorry for the double post, if it is.


Sup, bitches :)

BBS Signature

Response to Foss: Recording W/ Bitmapdata 2005-10-28 17:12:46


liam can you come on msn?

Response to Foss: Recording W/ Bitmapdata 2005-10-28 17:15:00


At 10/28/05 05:06 PM, -liam- wrote:
At 10/28/05 05:02 PM, fwe wrote: It requires 8 bits, not bytes, and 8*4 is 32 :)
I thought bits were bytes, and I misread.. heh, now I look stupid :)

Lolyeah, also, for not knowing that 8 * 4 is 32, haha. I learn it about three years ago, or maybe two.


BBS Signature