I’m trying to slowly make the switch from C-Style programming to OOP, so forgive me if this complaint is painfully obvious. I wanted to try using my own classes to create elements of the world. I can’t help but feel like I’m still imagining everything to be too function-based but I wanted something essentially like createTree(x,y,z). So, for testing I did createBox(material) instead, and put it under a ‘world’ class: world.createBox(material).
Doing this made my FPS drop from 50-60 to 3-4.
public class Main extends SimpleApplication {
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Geometry box1 = world.createBox(mat);
rootNode.attachChild(box1);
}
}
The above code is part of the default Main.java that you get when creating a new project in the SDK. The following is my class, it is found in the same destination as Main.java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mygame;
/**
*
* @author Lou
*/
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
public class world {
public static Geometry createBox(Material mat){
Box b = new Box(Vector3f.ZERO, 1, 1, 1);
Geometry geom = new Geometry("Box", b);
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);
return geom;
}
}
Am I using classes wrong?
I should add that the rendered result is the same.