Doubt about ScreenGraphAdaptor

Hi. I was reading about traversing the screengraph using an adapter. I saw the following example at github:

https://github.com/jMonkeyEngine/BookSamples/blob/master/src/chapter07/LoadEffectFromJ3o.java

     SceneGraphVisitorAdapter myEmitterVisitor =new SceneGraphVisitorAdapter() {
    @Override
    public void visit(Geometry geom) {
        super.visit(geom);
        searchForEmitter(geom); // trigger custom test
    }

    @Override
        public void visit(Node node) {            
        super.visit(node);
        searchForEmitter(node); // trigger custom test
    }

    private void searchForEmitter(Spatial spatial) {
         // specify search criteria, e.g. class, name, properties
        if (spatial instanceof ParticleEmitter) {
          System.out.println("Emitter in "+ spatial.getName());
        // modify the found node:
        ((ParticleEmitter)spatial).setNumParticles(10);
        }
    }
};

My doubt is why is the visit method is called on super? Shouldn’t the code work without this step?

Well its not needed, but you never know what a super implementation does.
In that case it does nothing so calling it does nothing.
So it’s safe to remove it here.

1 Like

Yeah, my guess is that someone let the IDE generate those methods or something.

Usually you don’t have to call super on adapter methods.

1 Like