Skip to content

camara‐en

JNightRide edited this page Dec 21, 2023 · 3 revisions

Camera

The default camera offered by JME is not configured for our 2.5D scenes. For this jMe3GL2 provides an object that solves this problem easily.

Camera2DRenderer camera2DRenderer = new Camera2DRenderer(Camera2DRenderer.GLRendererType.GL_2D, 4.5F, 0.01F);
camera2DRenderer.getJme3GL2Camera().setProperty("InterpolationByTPF", false);
stateManager.attach(camera2DRenderer);

There are 2 types to manage the camera:

  1. GLRendererType.GL_2D: Configure the camera with a parallel projection (this helps the depth of the sprites placed in the scene not have direct interaction with the camera).
  2. GLRendererType.GL_3D: This type allows us to use the 3D camera in a 2D scenario, with this we can use functions or objects dedicated to 3D in JME3 without limiting ourselves or creating our own (such as some post-processed ones).

Follow a model

In games it is very common for the camera to follow a target, we can achieve this in the following way:

....
camera2DRenderer.setTarget(geom);
...

Limiters

We can remove the camera by following a target or moving it to a certain desired distance.

....
/* a clipping. */
camera2DRenderer.setClipping(new Vector2f(0, 0), new Vector2f(20, 20);
        
/* off-set */
camera2DRenderer.setOffset(new Vector2f(2, 3));
....

Next

Clone this wiki locally