Hello,
I am trying to create a minecraft-like inventory system using Lemur. To do this, I have geometries that represent inventory items added to a SpringGridLayout.
Here is my code:
@Override
protected void setupGui(){
container = new Container(new SpringGridLayout(Axis.X, Axis.Y));
container.addChild(new Label("Inventory"), 0, 0);
Material mat = new Material(getApp().getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Green);
for(int x=0;x<8;x++){
for(int y=1;y<=4;y++){
Geometry geometry = new Geometry("inventory-" + x + "," + y, new Box(1, 1, 1));
geometry.setMaterial(mat);
geometry.setLocalScale(16);
geometry.rotate(new Quaternion().fromAngleAxis(toRadians(-25), Vector3f.UNIT_X));
geometry.rotate(new Quaternion().fromAngleAxis(toRadians(-45), Vector3f.UNIT_Y));
Node node = new Node(); //a similar error that requests a node occurs when the inventory item is attached directly
node.attachChild(geometry);
container.addChild(node, x, y);
}
}
container.setLocalTranslation(getApp().getCamera().getWidth() / 2 - container.getSize().length() / 2, getApp().getCamera().getHeight() / 2 - container.getSize().getY() / 2, 0f);
getApp().getGuiNode().attachChild(container);
}
private float toRadians(float degrees){
return (degrees / 180) * FastMath.PI;
}
When I run it I get the following error:
java.lang.IllegalArgumentException: Child is not GUI element.
at com.simsilica.lemur.component.SpringGridLayout.addChild(SpringGridLayout.java:326)
at com.simsilica.lemur.component.SpringGridLayout.addChild(SpringGridLayout.java:392)
at com.simsilica.lemur.Container.addChild(Container.java:112)
at src.john01dav.lemurlearning.InventoryGuiAppState.setupGui(InventoryGuiAppState.java:40)
at src.john01dav.lemurlearning.GuiAppState.initialize(GuiAppState.java:15)
at com.jme3.app.state.AppStateManager.initializePending(AppStateManager.java:251)
at com.jme3.app.state.AppStateManager.update(AppStateManager.java:281)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:236)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:193)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
at java.lang.Thread.run(Thread.java:745)
The only reason I would use Lemur over Nifty (or even just somehow embedding Swing) is because of it’s inherent ability to use 3D objects as described in other threads.