Hi Dan,
I am making a device orientation game.
I'm trying to make my "enemy" which is an alien spawn randomly across the screen with fade in and fade out. However, either it fades in and doesn't fade out, or vice versa.
Here is my beam: kanwalmobile4
Best,
Kanwal
Hi Kanwal,
The needs the time in seconds as the first parameter - timeout(time, function). Or you could use a rewind:true and possibly a rewindWait:2 or whatever.
new Circle()
.center()
.alp(0)
.animate({props:{alpha:1}, rewind:true, call:()=>{}});
I got it fading in and out, but how do I get it to respawn after 3 seconds at a random location after that?
this is my code for spawning it currently:
function spawnAlien() {
if (alien) {
alien.removeFrom();
alien = null;
}
alien = new Pic(ASSET_PATH + "alien.png")
.addTo(bounds)
.sca(2)
.loc(rand(bounds.width - 200), rand(bounds.height - 200))
.alp(0)
.top();
alien.animate({
props: { alpha: 1 },
time: 1,
rewind: true,
rewindWait: 3,
call: () => {
alien.removeFrom();
alien = null;
timeout(spawnAlien, 3);
}
});
S.update();
}
spawnAlien()
Other way around again on the timeout() so timeout(3, spawnAlien);
Thank you! That worked! Finally, the missing piece of my puzzle. Thanks so much for all your help!!
1 Like