Camera fading issue?

so i’m trying to get my camera to fade to black, then reset the scene WITHOUT going back to the scene first. how do i instead of this flickering from black back to the scene, make it so it fades to black, restarts the scene & THEN fades back into the game? for some reason, this does a thing where it fades to black, waits a second or 2, goes to the scene, then runs the scene like normal after 2 seconds of waiting?

// `Shake` the Camera to show `death`

__camera.shake ( 100, 0.05 );

// `Fade` the Camera out with a 250 millisecond delay

__camera.fade ( 250, 0, 0, 0, false, ( __camera, __progress ) => {
    if ( __progress > 0.999 ) {
        __scene.restart ( );
    }
} );

ANY help as always is GREATLY appreciated!

Thank You! :slight_smile:

I make this effect by using a black sprite over the top of scene. And so I chance its alpha, going from 0 ato 1, ou from 1 to 0, depends of what I want, if make black or make clear.

What happens if you restart the scene only (no camera effects)?

@samme : it doesn’t work the way it’s supposed to. It just resets with no fade.

Yes, but does the scene restart correctly? Is there a delay?

this.time.addEvent({
delay: 200,
callback: function(){
__scene.restart();
}
})

@samme : a split-second delay as far as i can tell.

@Villan : Uncaught TypeError: Cannot read property ‘addEvent’ of undefined

When you restart a scene, an entirely new main camera is created, with no effects running. That’s normal. You would have to fade in again from there.

I don’t see where a long delay could be coming from. Try adding some logging.

@samme : there is supposed to be a 250 millisecond delay, a black fade out, a scene fade in then a scene reset.

__camera.fade ( 250, 0, 0, 0, false, ( __camera, __progress ) => {
	if ( __progress > 0.999 ) {
		__scene.restart ( );
	}
} );

Here is camera fade out, restart, fade in:

From the code you’ve shown, I don’t see where a 1 or 2 second delay could be coming from. Add some logging. You need to figure out what the scene is actually doing during that time.