JME task

Hi Guys,

Im a newbie just need few good ideas how I have to tackle this problem(task :D)

task: "write an JME application with a custom app state which after 5 seconds creates a node (can be a simple 3d shape) with a custom control and attaches it to the scene. The custom control should remove the node again when the camera gets too close to the node (“user collects the node”)
"

I created a 3d shape with blender, but the problem for me is at the moment how this shape appears each 5 seconds …any ideas?

So you assume your teacher doesn’t have internet? Whats your code at the moment? Whats the problem?

1 Like

nahhh its not a teacher, its just a “test” to see how I learn new " skills",
I took the code from this page and wanted to load an 3d shape, but then I have no ideas…

public class TestAppStates extends Application {

public static void main(String[] args){
    TestAppStates app = new TestAppStates();
    app.start();
}

@Override
public void start(JmeContext.Type contextType){
    AppSettings settings = new AppSettings(true);
    settings.setResolution(1024, 768);
    setSettings(settings);
   
    super.start(contextType);
}

@Override
public void initialize(){
    super.initialize();

    System.out.println("Initialize");

    RootNodeState state = new RootNodeState();
    viewPort.attachScene(state.getRootNode());
    stateManager.attach(state);

    
    Spatial model = assetManager.loadModel("Models/Teapot/Teapot.obj");
    model.scale(3);
    model.setMaterial(assetManager.loadMaterial("Interface/Logo/Logo.j3m"));
    state.getRootNode().attachChild(model);

    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,
                                                       inputManager,
                                                       audioRenderer,
                                                       guiViewPort);
    niftyDisplay.getNifty().fromXml("Interface/Nifty/HelloJme.xml", "start");
    guiViewPort.addProcessor(niftyDisplay);
    
}

@Override
public void update(){
    super.update();

    // do some animation
    float tpf = timer.getTimePerFrame();

    stateManager.update(tpf);
    stateManager.render(renderManager);

    // render the viewports
    renderManager.render(tpf, context.isRenderable());
}

@Override
public void destroy(){
    super.destroy();

    System.out.println("Destroy");
}

}

You can schedule (eg via regular Java timer) a Callable , that app.enqueue an other Callable that add the node.

Step one:
Never do this:
public class TestAppStates extends Application

It’s ok for that particular test application but you should always extend SimpleApplication for your own games.

Step two:
time += tpf;
if( time > 5 ) {
//do the thing after five seconds
}

…either in an app state’s update() method or simpleUpdate() override of SimpleApplication.

And if you can’t figure out how to proceed from that description then keep learning Java until it makes sense. It’s a good initial learning exercise.