Fade in / Fade out. Does it work?

Hey guys, I had the fade in fade out working and not sure why it’s not working anymore. The code was very simple and exactly as it’s mentioned in the wiki, I implemented and it worked, now it doesn’t.



Here’s my code (nothing happens), please advise:



[java]

package mygame;



import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.post.FilterPostProcessor;

import com.jme3.post.filters.FadeFilter;

import com.jme3.renderer.RenderManager;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;



/**

  • test
  • @author normenhansen

    */

    public class Main extends SimpleApplication {





    private FilterPostProcessor fpp;

    private FadeFilter fade;





    public static void main(String[] args) {

    Main app = new Main();

    app.start();

    }



    @Override

    public void simpleInitApp() {

    Box b = new Box(Vector3f.ZERO, 1, 1, 1);

    Geometry geom = new Geometry("Box", b);



    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

    mat.setColor("Color", ColorRGBA.Blue);

    geom.setMaterial(mat);



    rootNode.attachChild(geom);

    }



    /**
  • function that results in a fade in effect at the beginning of the
  • animation

    *
  • @boolean

    */

    private void fadeInEffect(boolean b) {



    if(b == true)

    {

    fpp = new FilterPostProcessor(assetManager);

    fade = new FadeFilter(5); // e.g. 2 seconds

    fpp.addFilter(fade);

    viewPort.addProcessor(fpp);

    fade.fadeIn();

    }



    }





    @Override

    public void simpleUpdate(float tpf) {

    //TODO: add update code



    }



    @Override

    public void simpleRender(RenderManager rm) {

    //TODO: add render code

    }

    }



    [/java]

…fadeInEffect is never called

sorry I wrote that testCase too quick, but even if I do nothing happens



[java]



package mygame;



import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.post.FilterPostProcessor;

import com.jme3.post.filters.FadeFilter;

import com.jme3.renderer.RenderManager;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;



/**

  • test
  • @author normenhansen

    */

    public class Main extends SimpleApplication {





    private FilterPostProcessor fpp;

    private FadeFilter fade;





    public static void main(String[] args) {

    Main app = new Main();

    app.start();

    }



    @Override

    public void simpleInitApp() {

    Box b = new Box(Vector3f.ZERO, 1, 1, 1);

    Geometry geom = new Geometry("Box", b);



    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

    mat.setColor("Color", ColorRGBA.Blue);

    geom.setMaterial(mat);



    rootNode.attachChild(geom);



    fadeInEffect(true);

    }



    /**
  • function that results in a fade in effect at the beginning of the
  • animation

    *
  • @boolean

    */

    private void fadeInEffect(boolean b) {



    if(b == true)

    {

    fpp = new FilterPostProcessor(assetManager);

    fade = new FadeFilter(5); // e.g. 2 seconds

    fpp.addFilter(fade);

    viewPort.addProcessor(fpp);

    fade.fadeIn();

    }



    }





    @Override

    public void simpleUpdate(float tpf) {

    //TODO: add update code



    }



    @Override

    public void simpleRender(RenderManager rm) {

    //TODO: add render code

    }

    }



    [/java]

call it in the simpleUpdate, but only once

still won’t work

mhh ok, before calling fadeIn() call fade.setValue(0); it should work

Great! it works great. Thanks the wiki didn’t mention that line but yeah it makes perfect sense now.

hey guys first post here, I am attempting to use this method in my basic hello world in jMonkey. according to the JavaDoc, it looks to me like I need:



import com.jme3.post.filters.FadeFilter;



however when I try doing that I am getting an error: The import com.jme3.post.filters cannot be resolved



therefore, can’t use it. Any advice?



thanks and sorry for spamming your topic

Filters has been split in their own jar recently, make sure you have JME3-effects.jar in your classpath

1 Like

I’m trying to do this with a 2D picture but it doesn’t seem to work:( I have two questions: can this work with 2D pictures and if it can, what am I doing wrong

Fade filter (the topic of this thread) fades the whole screen to/from black.

This has nothing to do with fading the alpha of some object and if that’s what you mean then you should start another thread and include more information on what you’ve tried that “isn’t working”, etc.