collinhover / impactplusplus

Impact++ is a collection of additions to ImpactJS with full featured physics, dynamic lighting, UI, abilities, and more.
http://collinhover.github.com/impactplusplus
MIT License
276 stars 59 forks source link

Fade 'level' in and out using camera atmosphere? #92

Closed arakash92 closed 11 years ago

arakash92 commented 11 years ago

So I'm trying to have my world/level fade in and out.

I have the following code:

camera.addAtmosphere(0);//turns to black instantly, right?
camera.removeAtmosphere(2);//fades out atmosphere over 2 seconds, right?

Doesn't seem to work :s

collinhover commented 11 years ago

The issue is likely that the atmosphere overlay is not yet added to the world when you remove it, so it never gets added at all. Remember that when you use ig.game.spawnEntity it creates the entity immediately, then puts the entity in a deferred list, and on the next update actually adds the entity to the game. Try this:

camera.addAtmosphere(0);
// check if atmosphere overlay is actually added to the game
if ( camera.atmosphereOverlay.added ) {
   camera.removeAtmosphere(2);
}
// otherwise, wait for the added signal and then remove
else {
    camera.atmosphereOverlay.onAdded.addOnce( function () {
       camera.removeAtmosphere(2);
    } );
}
arakash92 commented 11 years ago

Ah, right. thanks!