SimpleJMEApplet tutorial problem

ha!, I think i got it… but I don’t know how to fix it. The ‘display_parent’ object should be initialized I think… but I don’t know how to do it… :confused:

think your using it wrong and shouldn’t have ‘Canvas display_parent’ in your class, I say this because BaseApplet (extended by BaseSimpleApplet) has ‘Canvas displayParent’ inside it which is initialised in its init() method.

i fixed the displayParent… but it is still not calling the simpleUpdate method… I dont know why the update is not being called X(



[java]public class AppletTestBoxColor extends BaseSimpleApplet {



private TriMesh t;

private Quaternion rotQuat;

private float angle = 0;

private Vector3f axis;



@Override

protected void simpleInitGame() {



System.out.println(displayParent);

try {

Display.setParent(displayParent);

} catch (LWJGLException ex) {

ex.printStackTrace();

}





lightState.setEnabled(false);

rotQuat = new Quaternion();



axis = new Vector3f(1, 1, 0.5f).normalizeLocal();



Vector3f max = new Vector3f(5, 5, 5);

Vector3f min = new Vector3f(-5, -5, -5);



t = new Box(“Box”, min, max);

t.setModelBound(new BoundingBox());

t.updateModelBound();

t.setLocalTranslation(new Vector3f(0, 0, -15));

rootNode.attachChild(t);



t.setRandomColors();



TextureState ts = display.getRenderer().createTextureState();

ts.setEnabled(true);

ts.setTexture(TextureManager.loadTexture(

TestBoxColor.class.getClassLoader().getResource(

“Monkey.png”), Texture.MinificationFilter.Trilinear,

Texture.MagnificationFilter.Bilinear));



rootNode.setRenderState(ts);

}



@Override

protected void simpleUpdate() {

if (tpf < 1) {

angle = angle + (tpf * 25);

if (angle > 360) {

angle -= 360;

}

}



rotQuat.fromAngleNormalAxis(angle * FastMath.DEG_TO_RAD, axis);

t.setLocalRotation(rotQuat);

System.out.println(“IT IS STILL NOT BEING PRINTED”);

}

}[/java]

not sure if simpleUpdate is suppose to be called every frame (jME noob here) but from looking at the source code for BaseSimpleApplet it is the update() which is called every frame, and simpleUpdate is only called once in there in the following section



[java]/**

  • If step is a valid command (via key ADD), update scenegraph one unit.

    */

    if (KeyBindingManager.getKeyBindingManager().isValidCommand(“step”,

    true)) {

    simpleUpdate();

    rootNode.updateGeometricState(tpf, true);

    }[/java]



    so unless the above if statement is true it won’t be called.



    Hopefully a more experience jME developer will be able to clear this up.

I’m reading this jME introduction, and at the end of page 19, it teaches how to add some code to run every frame… and it tells to use simpleUpdate :confused:

I know that is not about applets, I think it should work the same, because if you look into the BaseSimpleApplet class, you will find this:

[java] /**

  • Can be defined in derived classes for custom updating. Called every frame
  • in update.

    */

    protected void simpleUpdate() {

    // do nothing

    }[/java]

In that case BaseSimpleApplet has a bug in the update() in that it does not call simpleUpdate() every frame.

I’m wondering if I should change the code of update method in BaseSimpleApplet, so it calls simpleUpdate… I will try this just to see what happens…

looks like, for some reason, this code will only run if the user presses “+” on the numpad… o.O



[java]if (KeyBindingManager.getKeyBindingManager().isValidCommand(“step”,

true)) {

simpleUpdate();

rootNode.updateGeometricState(tpf, true);

}[/java]



I tested it, when I press “+” during the execution, the applet executes my simpleUpdate method (but it still not showing anything on the screen)