Fix camera init/shutdown
This commit is contained in:
@@ -4,38 +4,46 @@
|
||||
import com.jme3.light.DirectionalLight;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.shadow.DirectionalLightShadowRenderer;
|
||||
import pp.mdga.client.MdgaApp;
|
||||
|
||||
public class CameraHandler {
|
||||
MdgaApp app;
|
||||
|
||||
private DirectionalLight sun;
|
||||
private AmbientLight ambient;
|
||||
|
||||
private static final int SHADOWMAP_SIZE = 1024 * 8;
|
||||
|
||||
|
||||
public CameraHandler(MdgaApp app){
|
||||
this.app = app;
|
||||
initCamera();
|
||||
|
||||
sun = new DirectionalLight();
|
||||
sun.setColor(ColorRGBA.White);
|
||||
sun.setDirection(new Vector3f(0.3f, 0, -1));
|
||||
|
||||
ambient = new AmbientLight();
|
||||
ambient.setColor(new ColorRGBA(0.3f, 0.3f, 0.3f, 1));
|
||||
}
|
||||
|
||||
private void initCamera() {
|
||||
public void init() {
|
||||
app.getFlyByCamera().setEnabled(true);
|
||||
int zoom = 15;
|
||||
app.getCamera().setLocation(new Vector3f(-zoom, 0, zoom));
|
||||
app.getCamera().lookAt(new Vector3f(0, 0, 0), new Vector3f(0, 0, 1));
|
||||
|
||||
DirectionalLight sun = new DirectionalLight();
|
||||
sun.setColor(ColorRGBA.White);
|
||||
sun.setDirection(new Vector3f(0.3f, 0, -1));
|
||||
app.getRootNode().addLight(sun);
|
||||
|
||||
AmbientLight ambient = new AmbientLight();
|
||||
ambient.setColor(new ColorRGBA(0.3f, 0.3f, 0.3f, 1));
|
||||
app.getRootNode().addLight(ambient);
|
||||
|
||||
DirectionalLightShadowRenderer dlsr = new DirectionalLightShadowRenderer(app.getAssetManager(), SHADOWMAP_SIZE, 4);
|
||||
dlsr.setLight(sun);
|
||||
app.getViewPort().addProcessor(dlsr);
|
||||
|
||||
app.getRootNode().addLight(sun);
|
||||
app.getRootNode().addLight(ambient);
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
app.getRootNode().removeLight(sun);
|
||||
app.getRootNode().removeLight(ambient);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package pp.mdga.client.view;
|
||||
|
||||
import pp.mdga.client.board.BoardHandler;
|
||||
import pp.mdga.client.board.CameraHandler;
|
||||
import pp.mdga.client.dialog.SingleButtonRightDialog;
|
||||
import pp.mdga.client.MdgaApp;
|
||||
import pp.mdga.client.MdgaState;
|
||||
|
||||
public class GameView extends MdgaView {
|
||||
private BoardHandler boardHandler;
|
||||
private CameraHandler camera;
|
||||
|
||||
private SingleButtonRightDialog continueButton;
|
||||
|
||||
@@ -14,6 +16,7 @@ public GameView(MdgaApp app) {
|
||||
super(app);
|
||||
|
||||
this.boardHandler = new BoardHandler(app);
|
||||
this.camera = new CameraHandler(app);
|
||||
|
||||
continueButton = new SingleButtonRightDialog(app, node, "Weiter", () -> app.enter(MdgaState.CEREMONY));
|
||||
}
|
||||
@@ -21,6 +24,7 @@ public GameView(MdgaApp app) {
|
||||
@Override
|
||||
public void onEnter() {
|
||||
boardHandler.init();
|
||||
camera.init();
|
||||
|
||||
continueButton.show();
|
||||
}
|
||||
@@ -29,6 +33,7 @@ public void onEnter() {
|
||||
public void onLeave() {
|
||||
continueButton.hide();
|
||||
|
||||
camera.shutdown();
|
||||
boardHandler.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user