today i ran into a problem with gradient masks. the problem seems to be that flash 8 does not appreciate a mask using a gradient to be itself masked by anything else. the effect that such a combination produces is a flickering of stage assets akin to compiling with an error in your code. after much experimentation i google'd something that led me to using the blend mode instead of cacheasbitmap/setmask. it works perfectly and is not a big deal to set up.
take your gradient mask symbol and change the blendmode to alpha (from the post i read erase works too but i haven't tried it since alpha worked). you can change the blendmode in a couple of ways. one way is in the flash ide. there is a blend mode drop down on the properties of the movieclip. another way is by code. reference the movieclip's blendMode property and assign it the string 'alpha'.
MovieClip.blendMode = 'alpha';
place the movieclip / shape being masked on a layer below your 'mask' but do not set either layer as a mask layer.
convert these two layers into its own movieclip.
set the blendmode of this combined movieclip to 'layer' using either of the above methods.
MovieClip.blendMode = 'layer';
if you used the ide to set the blend modes then you will be able to see the effect immediately. if you used code you'll have to compile.
Monday, April 30, 2007
Friday, April 20, 2007
Trigonometric Baby Steps
I've taken my first steps at learning trigonometry this week. I've been working on a game that uses pseudo-trajectory and mathematical collision detection. I thought it a good chance for me to dunk my head into the quicksand that is trig.
My most used function? Math.atan2. I can't recommend it enough for finding angles. The basics of it goes like this:
ObjectA has an X and a Y coordinate and ObjectB also has an X and a Y coordinate. Start with one object (I'll start with ObjectA) and subtract each axis from each other.
var nRun:Number = ObjectA._x - ObjectB._x;
var nRise:Number = ObjectA._y - ObjectB._y;
Math.atan2 takes these two numbers as arguments like so:
var nRadians:Number = Math.atan2(nRise,nRun);
There you have it. You now know, in radians, what angle ObjectA points at ObjectB. If you want to see it in degrees so you can rotate your movie clip:
var nDegrees:Number = nRadians / Math.PI * 180;
My most used function? Math.atan2. I can't recommend it enough for finding angles. The basics of it goes like this:
ObjectA has an X and a Y coordinate and ObjectB also has an X and a Y coordinate. Start with one object (I'll start with ObjectA) and subtract each axis from each other.
var nRun:Number = ObjectA._x - ObjectB._x;
var nRise:Number = ObjectA._y - ObjectB._y;
Math.atan2 takes these two numbers as arguments like so:
var nRadians:Number = Math.atan2(nRise,nRun);
There you have it. You now know, in radians, what angle ObjectA points at ObjectB. If you want to see it in degrees so you can rotate your movie clip:
var nDegrees:Number = nRadians / Math.PI * 180;
Subscribe to:
Posts (Atom)