kaboom
kaboom copied to clipboard
Fade Support?
Is it possible to implement a function to fadeIn or fadeOut sprites / obj?
It's a good idea for a custom component:
function fadeIn(speed = 1) {
let opacity = 0;
return {
// runs when object is added to the scene
add() {
this.color.a = opacity; // make sure the game object using this component has `color()` component
},
// runs every frame when object is still in the scene
update() {
if (opacity < 1) {
opacity += dt() * speed;
this.color.a = opacity;
}
},
};
}
add(
sprite("birdy"),
color(),
);
Hmm, that example didn't work for me there is no movement whatsoever.
I thought more like:
add([
sprite("mark"),
scale(2),
fadeIn(0, 2), // fadeIn(From, To) in seconds.
]);
When you want to have it repeat like a loop then it could be like this:
add([
sprite("mark"),
scale(2),
fadeIn(0, 2, 1), //FadeIn (From, To, loop), While 1 is on and 0 is off.
]);
With that it would play the loop and just return to the 0 state and start over again.
But what if you want to have like a logo appear and then disappear then I could look like this:
add([
sprite("mark"),
scale(2),
fade(0, 2, 5, 0); // fade(From, To, Wait, off),
]);
Going from 0 to 2 Seconds and wait 5 seconds (or more) and back to 0.
added in dcb055d596aeb0a23214291349aad2bcd8f8a617