Binary Video Colour Collision Detection AS3 - actionscript-3

So I've got a field of yellow balls on the stage in rows all the way down the screen. About 200 of them. They're all movieClips linked from one ball MovieClip in the library.
I'm storing them in an Array called ballField.
I've also got a video feed on the stage (right now from webcam, but later will be whatever video I choose).
I want the video to be broken down into binary colour (black and white contrast).
Then I want to hit test all of the balls MovieClips against the color white from the video on enter frame.
Whenever a ball is 'hit' I want it to become visible. Whenever it's not hit, it will be invisible.
Essentially I want the end product to be a video created out of a field of balls (each ball would be like a binary pixel) appearing and disappearing against the white motion of the background video, (once it's working I'll hide the source) to give the illusion of a video created out of yellow balls.
This is a little over my head. I researched several options using the Bitmap data class for collision detection, but I'm not sure how to hitTest colours versus points. And I'm not sure how to hitTest bitmap data from a video to a MovieClip.
Any help is appreciated..

Hrm, one way I see to do this is for every ball, get the position of it and compare it to the pixel on the video it is supposed to match (may need to do some of your own mapping logic here). Then just look up that pixel colour to determine if the ball is visible or not. No hitTesting needed.

Related

How do i create an animation in AS3?

I am making a game in AS3 for a school project (using the AIR api). I have about a year's worth of experience in AS3, so i would say i'm proficient but not an expert. Anyway, i have never attempted to do sprite animations in AS3 and i'm not quite sure how to approach it.
If i create a list of bitmaps and call addChild() and removeChild() to display each frame of the animation, it would affect the framerate as these functions are not very efficient (i have tried this before and it tanked my framerate if i had too many animations going at once). I have also tried creating a list of BitmapData objects, adding a bitmap to the display list, and then pointing it to a different BitmapData each frame, but this does not seem to work at all.
So what is the best way to do this? In XNA, for example, i would create a sprite class that draws to the screen using a sprite batch, then i would create a list of sprite objects and cycle through them to create the animation. Is there any way to achieve a similar result in actionscript?
First (simple) method: you can just use multi-frame MovieClip for animation. Put an image in each frame, put a MovieClip on the stage and that's all. You can control this animation using play(), stop(), gotoAndPlay(), gotoAndStop(). It will work without much problems for a generic platform game (I did that myself long ago).
Second (advanced) method: use bitmap blitting. For each animation, create a bitmap image that holds each frame of the animation. Use this image as a source for copying pixels into your current animated object. You just need to copy a particular rectangle area inside a source bitmap that corresponds to the current frame.
The actual blitting happens here
destinationBitmapData.copyPixels(sourceBitmapData, areaRectangle, destinationPoint);
Where destinationBitmapData is your "canvas" that you're blitting to; sourceBitmapData is the source image holding all animation frames; areaRectangle is the Rectangle inside the source image defining which area to copy; destinationPoint is left-top coordinate of the copy area in your canvas.
The destination canvas can be just one small object (like your game character that is moving around) or the entire game screen with all objects. I.e. instead of blitting and adding each object separately, you can just have one big canvas and blit any necessary parts directly to it.
That said, there is already a number of various ready-made engines that use blitting and even advanced techniques like 3D acceleration for 2D sprites.
One of them is Starling.

Actionscript 3 - Bitmaps and Symbols

I am working on flash professional cs5.5 and actionscript 3. I need to use symbols of customized sizes to test the hitTestOjbect() function. However, when i convert the bitmap to a symbol, by default it goes into a rectangular size and the empty space all around is also detected as part of the symbol.
Is there any way to keep the size of the symbol customized ?
That is the nature of a bitmap. Technically, bitmaps are always rectangular. Transparent areas are just fills with alpha-0. When you convert a bitmap to a symbol, the bitmap still exists, just inside the context of the symbol.
One of the fastest ways to fix this is to use a mask inside your MovieClip. Create a plain drawing object in the exact shape of the hit area you want. Then, place that on your timeline on it's own layer. Right-click the layer with the mask, click "Mask", and then drag the bitmap's layer under the mask one. Lock both layers, and exit symbol editing.
Now your hit area will be limited to only the masked area.
EDIT: I appear to be mistaken - hitTestArea is always rectangular. See the top answer to hitTestObject Collision Not Registering Correctly.

How do I make an object turn black, when a movie clip animation turns black?

I have a light bulb movie clip, where it glows and burns out. I want everything in the scene to turn black when it does burn out. Like objects, movieclips, and arrays. When the light bulb comes back on, I want the objects to turn back to their original color. How do I do this?
Simple way would be to just create a black rectangle and add it to the stage when you want the lights to go out.
When you want the lights back, just remove it from the stage.
You could also adjust the alpha of that black rectangle over time or tween it to have it gradually turn black. When the rectangle has alpha set to 0, everything else's color will be as if the lights are on. Alpha set to 1, would be complete darkness.
Update - now that you have changed the question in the comments of the question by adding details that would have been helpful from the beginning :
You can use ColorTransform to change the color of your fireflies to black. Google that or search that on this site for detail.
Also, you can do this effect in the IDE by setting one frame as normal, and in another frame tint it black using a color effect on the properties panel. (Not sure what version of the IDE you have, it might be labeled differently in earlier versions)

Draggable object with multiple boundaries

I have my player dragged around the stage. If the player hits any object(All perfect rectangles) that I lay out in a movieclip, I'd like the player to hit a wall and stop moving. What's the most efficient way to write this?
Do I loop through all the points the player can't hit?
There are built in methods for hit testing, you loop through all the objects you want to hit test against (make each it's own sprite or hit test the entire sprite that contains all the parts against the object depending on what kinds of info you want to have. You may also want to rig up your own custom Sprite that has hit regions for the left right top and bottom to determine which edge the player has hit.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#hitTestObject()
Multiple hittest AS3

Drawing the exact region of the Bitmap in as3

I am working on a Action Script 3.0 application , in which i ill be allowed to load the image and make them draggable. Consider i am loading the deer image and making it as draggable.
Problem with this is , if i click on the translucent area ( white space around the bitmap ), i dont want the bitmap to draggable.is there any way to draw the deer boundary region exactly without the white space around it.
You can use BitmapData methods to get each pixel color, and then, you can either :
On creation, for each pixel if it's not fully transparent (!= 0) you can draw a point of a Shape, which will be transparent, and make it dragable in place of your bitmap (as noticed in comment, it will be quite CPU consuming, so use the second method)
On click, get the click coordinate relative to the bitmap, check if the pixel is transparent and make it drag only if it's not.
In either way, that will be quite CPU consuming. You may also consider convert your bitmap to a vector image (Sprite). This will allow flash to detect real images boundaries.