123456789101112131415161718192021222324252627282930313233343536373839404142 |
- = Fade-in / Fade-out Effect
- :author:
- :revnumber:
- :revdate: 2016/03/17 20:48
- :relfileprefix: ../../
- :imagesdir: ../..
- ifdef::env-github,env-browser[:outfilesuffix: .adoc]
- 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()`.
|