1234567891011121314151617181920212223242526272829303132333435363738 |
- = Fade-in / Fade-out Effect
- :revnumber: 2.0
- :revdate: 2020/07/25
- You can use a fade in/fade out effect to make smooth transitions, for example between game levels. The effect fades in from black to the initialized scene, or fades out from the scene to black.
- The effect uses com.jme3.post.FilterPostProcessor and com.jme3.post.filters.FadeFilter.
- == Setting up
- . Create one FilterPostProcessor object per application.
- . Create a FadeFilter object.
- . Give the FadeFilter constructor the fade duration in seconds as parameter. If you use the parameter-less constructor, the duration is 1 sec by default.
- . Add the FadeFilter to the FilterPostProcessor.
- . Add the FilterPostProcessor to the default viewPort.
- [source,java]
- ----
- private FilterPostProcessor fpp;
- private FadeFilter fade;
- public void simpleInitApp() {
- ...
- fpp = new FilterPostProcessor(assetManager);
- fade = new FadeFilter(2); // e.g. 2 seconds
- fpp.addFilter(fade);
- viewPort.addProcessor(fpp);
- ...
- }
- ----
- == Fading in and out
- Now call the `fade.fadeIn()` and `fade.fadeOut()` methods to trigger the effect.
- You can also change the fade duration using `fade.setDuration()`.
|