Reputation: 388
I am using a For Statement
clock with Haxe and OpenFL, to create a Fade In & Fade Out effect for a Bitmap object (using alpha
property). Do you have use other methods for that?
I am using a For
statement instead of Sys.sleep(0.2);
because it makes a "Loading" cursor icon and the program gets stuck.
The bitmap is called bmp
and the timer is tmrSplash
.
Source:
tmrSplash.run = function changeAlpha(): Void {
var f: Float = 1;
while (f <= 1 && f >= 0) {
bmp.alpha = f;
var a: Int = 0;
while (a < 500000000) {
a++;
if (a >= 500000000) {
a = 0;
}
f -= 0.0005;
trace(f);
}
tmrSplash.stop();
}
}
Thank you.
Upvotes: 0
Views: 1094
Reputation: 10143
In order to fade out manually, you'll need to listen to the ENTER_FRAME
event on the stage and change the value over time, instead of creating this infinite loop.
But I would suggest to take a look into a tween engine, like Actuate, which simplifies the syntax. You dont want to create something like this yourself, just use a library to animate properties. https://github.com/openfl/actuate
Actuate.tween (mySprite, 1, { alpha: 0 }); // fade out
Life is too short to invent another tween engine, dont waste your time on building such.
Upvotes: 5