0
我剛剛拿起jMonkeyEngine,遇到了一個我似乎無法解決的問題。爲什麼我的幾何體不會出現? (jMonkeyEngine)
在主類的simpleInitApp
方法,我可以使用下面的代碼成功地使一個盒子:
Box playerBase = new Box(Vector3f.ZERO,1f,1f,1f);
Geometry playerBaseGeom = new Geometry("playerBase", playerBase);
Transform fixBaseHeight = new Transform(
new Vector3f(0f,(0.5f * 2f),0f));
playerBaseGeom.setLocalTransform(fixBaseHeight);
Material playerBaseMaterial = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
playerBaseMaterial.setColor("Color", ColorRGBA.Yellow);
playerBaseGeom.setMaterial(playerBaseMaterial);
rootNode.attachChild(playerBaseGeom);
我試圖用一種叫做Tower
類能夠釀出代表塔好幾箱(爲一個簡單的塔防遊戲)。塔類看起來是這樣的:
public class Tower {
private static final float HEIGHT = 0.5f;
private static final float WIDTH = 0.2f;
private static final float DEPTH = 0.2f;
private Geometry towerGeom;
private Material towerMaterial;
private Box tower;
public Tower(AssetManager assetManager, float x_coord, float z_coord) {
tower = new Box();
towerGeom = new Geometry("tower", tower);
towerMaterial = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
towerMaterial.setColor("Color", ColorRGBA.Green);
towerGeom.setMaterial(towerMaterial);
towerGeom.setLocalTranslation(x_coord, (0.5f * .5f),z_coord);
towerGeom.setLocalScale(WIDTH, HEIGHT, DEPTH);
}
public Geometry getGeometry() {
return towerGeom;
}
}
在主類,在simpleInitApp
的方法,我試圖用我的新Tower
類是這樣的:
List <Tower> towers = new ArrayList<Tower>();
towers.add(new Tower(assetManager, 10f,8f));
for(Tower t:towers) {
rootNode.attachChild(t.getGeometry());
}
但是,沒有立方體呈現。爲什麼?我使用了開始時顯示的完全相同的過程,它的工作。
不要忘記照明。 – markspace