|
-
Senior Member
change alpha using integers
I have a simple script that fades a MC in or out.
All I want to do is decrease the alpha gradually by .1.
But it seems to be decreasing by many decimal places, rather than just -.1;
Is there a way to use only whole numbers like .8 as opposed to .723342?
Thanks, all.
Example:
var fade:Number = -.1;
box_mc.alpha += fade;
-
.8 isn't a whole number.
alpha only has 255 (I think. Could be a different number) different available values between 0 and 1, and it simply picks the one closest to the number you give it.
-
Senior Member
Yes, you're right..."whole number" isn't what I meant.
I guess what I mean is, how can I increment the alpha up or down using only +.1 or -.1. ?
-
What you've done is just about as close as you can get. One thing that may avoid compounding of rounding errors would be to keep the current ideal alpha separate from the actual alpha value:
Code:
var fade:Number = -.1;
var idealAlpha = 1;
while (idealAlpha >= 0){
idealAlpha += fade;
box_mc.alpha = idealAlpha;
}
The actual alpha values will still end up quantized to the allowed 255 values, but this way you're guaranteed to get the values closest to 1, .9, .8, etc.
-
Senior Member
cool!
Thanks.
I'll try it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|