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

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)

Related

AS3 Bitmap black and white - for compression reasons

I have a field made up of BitmapData, which I use for pixel-precise hit detection.
However, BitmapData naturally stores 2^32 (or 2^24 with no alpha?) possibilities for each pixel. I only need 2 - black or white.
But I still need to use .draw to make other objects being drawn onto that BitmapData. It doesn't need to be visible.
Extracting a pixel for hit-detection does not seem too difficult - but drawing without cycling through each pixel seems hard. Is it possible?
What would the right approach for this problem be?
If you depend on having your bitmap data to be black or white only, you can employ BitmapData.threshold() after drawing a new mask over that bitmap. To turn your existing BitmapData to black and white with a threshold of half red channel do the following:
bd.threshold(bd,bd.rect,new Point(),"<",0x00800000,0x0,0x00ff0000,true);
bd.threshold(bd,bd.rect,new Point(),">=",0x00800000,0x00ffffff,0x00ff0000,true);
The first call with turn all points that have red below 0x80 black, the second will turn all the remaining points white. Change the mask and threshold value to use green or blue channels if you want. Consider applying a properly channeled ColorTransform object to your draw calls to make the mask correctly applied to a newly drawn object.

Binary Video Colour Collision Detection AS3

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.

HTML5 - Canvas, layers, copy

so what I want to achieve is drawing a rectangle with either a color/fillRect or with clearRect and then copy it to the other canvas layer under the one I was drawing on. Also I want to set a background to this layer with opacity.
What I've tried is setting background with fillStyle and fillRect and it went fine. Also I could draw the rectangle with fillRect on the upper canvas which had no background and then copy the rectangle to the other one with drawImage.
Problem was when I tried to create a rectangle with clearRect and copy it. As I noticed I can only clearRect with another rectangle. But then I have to set a background to the upper canvas, which is ok, but when I copy it to the other one it gets darker and darker every time (well of course..)
So how is this possible?
When you work with alpha channel you will as you already noticed accumulate alpha channel values as long as alpha < 255. The only way to "reset" this is to start fresh so-to-speak.
Here are a couple of options to get around this -
Option 1
Don't copy anything from the draft canvas to the main canvas but store all points and shapes into a 2-dimensional array or an array consisting of the shape objects with its points, color, line width and so forth.
When you need to update the main canvas, clear both canvases and then re-render all the shapes to the main one.
Option 2
If all shapes on the main canvas is suppose to have the same opacity then use a third off-screen canvas. Draw everything to this canvas non-transparent (this last is important).
When updating main canvas clear it, set globalAlpha on it and then draw the off-screen canvas to it.
So we'll probably need some example code, because I'm not 100% sure what your trying to do... your using 2 canvas objects, drawing on the top canvas, and copying that to the bottom canvas... something like?:
ctx2.drawImage(canvas1,0,0);
then your clearing the top canvas:
ctx1.clearRect(0,0,canvas1.width,canvas1.height);
and doing your draw routine again? are you trying to get some sort of trail effect or something?

HTML5 canvas - opacity problem with a paint app

I'm trying to program a paint application using Canvas.
the way it works is by connection lines when the mouse is pressed.
when the line is opaque it works well, but when I change the alpha parameter I get a problem.
I tried two options:
a. The path begins when the mouse is down for the first time and ends when the mouse is up again:
every move of the mouse calls the stroke() function. because the line is transparent the beginning of the whole path will become opaque and the end won't, because stroke() is called many times, and it drwas the whole path again and again.
b. The path begins and ends every move of the mouse:
the line is transparent through the whole way, but the matching point between every path and path are less transparent (because they're made of two lines). so the whole path is not solid.
the only way I get a good result is when I call stroke() only when the mouse is up again. then it strokes the whole path well, but I see nothing while actually drawing it.
what can I do?
thanks
I think your best bet is to create a second overlay canvas that is positioned (using absolute positioning) over your primary canvas.
During a mouse drag, for every mousemove event use a clearRect() to clear your overlay canvas and then draw the entire stroke-in-progress.
When you get a mouseup, clear the overlay and draw the entire stroke to the primary canvas.
Here's a live example:
http://jsfiddle.net/rnNFB/1/

How to specify the "background" for BlendMode.ADD?

I am developing a flash game entirely in FlashDevelop, i.e., only with AS3 code.
I want to do the following: blend, as ADD (adding their colors), a couple of moving DisplayObjects, such that the blending occurs only between them, and not with anything else in the screen.
With no success, I've tried to do this: insert the moving DisplayObjects in a parent DisplayObject named container with blendMode as ADD, while all the rest of the game has blendMode NORMAL. I've also tried to set the blendMode of the moving DisplayObjects as ADD, with container.blendMode == NORMAL, with also no success.
Adobe's AS3 API mentions that the ADD Blend mode "Adds the values of the constituent colors of the display object to the colors of its background". How to control what this background is?
The background is anything with a lower depth than the movieclips that you're adding. So, whatever you had addChild()ed before those. It can also be the background color of the movie. Make sure that you are using a background color by using the backgroundColor parameter of the SWF tag (ie. [SWF(backgroundColor="#000000")]).
Everything in your game has to blend somehow with the DisplayObjects behind them, so it's hard to see what you need without seeing your specific example. At first hunch, try ADDing everything together in a single Sprite with a black background and then use BlendMode.LIGHTEN, BlendMode.SCREEN, or BlendMode.OVERLAY for that container Sprite.