00:00
00:00
Newgrounds Background Image Theme

JalenBrah 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:BitmapData - basic

10,179 Views | 39 Replies
New Topic Respond to this Topic

Response to AS:BitmapData - basic 2006-09-02 14:18:30


Oh noes Liam, never use putfile.com. They delete files after a month or two, use imageshack! Now I can't see the samples :(


BBS Signature

Response to AS:BitmapData - basic 2006-09-02 15:13:15


I have a question! I want to know how to delete certain shapes out of bitmaps. Like cutouts of em. Just like making an eraser clip that can be any shap and you move it along the bitmap and erase the pixels. Like what was done Here . They just had a rock hit the bitmap and erase or cut out the part it was overlaping. How do I go about doing that?

Response to AS:BitmapData - basic 2006-09-04 22:33:54


I considered wipping up a new thread but due to AS: Main being dead I decided to just post it here. If you have a bitmap in your library that for whatever reason you want to convert to grayscale you can do it with the function I wrote just to play with the bitmapData class tonight:

import flash.display.BitmapData;
function attachAsGrayscale(linkage, instance, depth) {
var myBitmapData:BitmapData = BitmapData.loadBitmap(linkage);
hexIndex = new Array("00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0A", "0B", "0C", "0D", "0E", "0F",
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1A", "1B", "1C", "1D", "1E", "1F",
"20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2A", "2B", "2C", "2D", "2E", "2F",
"30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3A", "3B", "3C", "3D", "3E", "3F",
"40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4A", "4B", "4C", "4D", "4E", "4F",
"50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5A", "5B", "5C", "5D", "5E", "5F",
"60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6A", "6B", "6C", "6D", "6E", "6F",
"70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7A", "7B", "7C", "7D", "7E", "7F",
"80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8A", "8B", "8C", "8D", "8E", "8F",
"90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9A", "9B", "9C", "9D", "9E", "9F",
"A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "AA", "AB", "AC", "AD", "AE", "AF",
"B0", "B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B9", "BA", "BB", "BC", "BD", "BE", "BF",
"C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "CA", "CB", "CC", "CD", "CE", "CF",
"D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9", "DA", "DB", "DC", "DD", "DE", "DF",
"E0", "E1", "E2", "E3", "E4", "E5", "E6", "E7", "E8", "E9", "EA", "EB", "EC", "ED", "EE", "EF",
"F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "FA", "FB", "FC", "FD", "FE", "FF");
for (var x:Number = 0; x<myBitmapData.width; x++) {
for (var y:Number = 0; y<myBitmapData.height; y++) {
pixel = myBitmapData.getPixel(x, y).toString(16);
while (pixel.length<6) {
pixel = "0"+pixel;
}
red = parseInt(pixel.slice(0, 2), 16);
green = parseInt(pixel.slice(2, 4), 16);
blue = parseInt(pixel.slice(4), 16);
avg = hexIndex[Math.round((red+blue+green)/3)];
pixel = "0x"+avg+avg+avg;
myBitmapData.setPixel(x, y, pixel);
}
}
this.createEmptyMovieClip(instance, depth);
this[instance].attachBitmap(myBitmapData, this.getNextHighestDepth());
}
//change stuff below here
attachAsGrayscale("easy2", "gray", _root.getNextHighestDepth());
gray._x = Stage.width/2;
gray._y = Stage.height/2;

I can't even imagine how NG's formatting is going to butcher that array.

Yes it is very slow and I probably will never use it in any Flash. Yes you could just as easily use photoshop to do the same at compile time rather than wasting resources at runtime.

For those interested the way it works is it loops through evey pixel in the bitmap using getPIxel. It then converts it to a hex RGB and breaks it up into the red green and blue values respectively. It takes the average of the 3 and then looks up that decimal in the hexIndex array to convert it back to hexidecimal. It then sets the pixel with the same averaged value for the red, blue and green channels so that the color will be a shade of gray.

Response to AS:BitmapData - basic 2006-09-04 22:37:22


Response to AS:BitmapData - basic 2006-09-04 23:45:00


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

its pretty easy, and this works realtime

Response to AS:BitmapData - basic 2006-09-05 01:01:12


At 9/4/06 10:33 PM, BleeBlap wrote: It takes the average of the 3 and then looks up that decimal in the hexIndex array to convert it back to hexidecimal.

you could just take the numerical value and say
avg = Math.round((red+blue+green)/3)
hex = avg << 16 | avg << 8 | avg;

no arrays, no hassle

Response to AS:BitmapData - basic 2006-12-15 19:09:59


Any questions?

I have one.How do you make a destructible terrain game?Cybex told me to lokk for bitmapdata threads and this was all I could find.So if you ever see this Liam,please help out

If you can help,please do so.

hello

Response to AS:BitmapData - basic 2007-01-24 15:19:09


Yeah lol!!! You write those uhh 100 odd lines... Or you could just use one of my 1 line algorythms :)

YourBitmap.applyFilter(YourBitmap, YourBitmap.rectangle, new Point(0, 0), new ColorMatrixFilter([0.212671, 0.715160, 0.072169, 0, 0, 0.212671, 0.715160, 0.072169, 0, 0, 0.212671, 0.715160, 0.072169, 0, 0, 0, 0, 0, 1, 0]));

Response to AS:BitmapData - basic 2007-01-24 15:29:20


At 12/15/06 07:09 PM, Tek-dude wrote:
Any questions?
I have one.How do you make a destructible terrain game?Cybex told me to lokk for bitmapdata threads and this was all I could find.So if you ever see this Liam,please help out

If you can help,please do so.

You're in luck! I just wrote a code for destroying a circular area of terrain!

(_x, _y, radius)
public function exploder(vx:Number, xy:Number, ve:Number):Void{
for(i = -ve; i <= ve; i++){
k = Math.round(Math.sqrt((ve * ve) - (i * i)));
for(j = -k; j < k; j++)
tre.setPixel32(vx - holder._x + i, vy - holder._y + j, 0x000000);
}
}

Srsly, you can do your collision detections based on getPixel, and blow up areas by simply changing their colours and alphas so that they no longer return true on any collision detections. There's a bitmap hittest function too, but I've never had any reason to use it.


BBS Signature

Response to AS:BitmapData - basic 2007-03-13 10:39:42


I made this a few days ago, following a tutorial for use with BitmapData I think. Was pretty cool!

Scroll over the RGB colour. I'm thinking of implementing a simple textbox that will put in the RGB color tag when you scroll over the colors. I also want to add in a text box so you can also add in your own colour tags and see the color. Anyone know how I would do this?

ColorPicker