-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Camera class to handle all updates etc of all the cameras that are used.
- Loading branch information
Kevin Söderberg
committed
Feb 12, 2018
1 parent
e2a7e53
commit 26beb9a
Showing
2 changed files
with
78 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.mygdx.game; | ||
|
||
import com.badlogic.gdx.graphics.OrthographicCamera; | ||
import com.badlogic.gdx.math.Matrix4; | ||
|
||
public class Camera { | ||
|
||
private final float WORLD_TO_RENDER = 96f; | ||
private final float RENDER_TO_WORLD = 1/96f; | ||
|
||
private OrthographicCamera worldCamera, lightCamera; | ||
private Matrix4 cameraBox2D; | ||
|
||
public Camera(float w, float h) { | ||
worldCamera = new OrthographicCamera(w, h); | ||
lightCamera = new OrthographicCamera(w*RENDER_TO_WORLD, h*RENDER_TO_WORLD); | ||
|
||
worldCamera.update(); | ||
lightCamera.update(); | ||
} | ||
|
||
//Character (x,y) and width & height | ||
public void update(float posX, float posY, float width, float height) { | ||
|
||
worldCamera.position.set((posX*WORLD_TO_RENDER)+ | ||
(width/2), (posY*WORLD_TO_RENDER)+(height/2), 0); | ||
|
||
lightCamera.position.set(posX, posY, 0); | ||
|
||
worldCamera.update(); | ||
lightCamera.update(); | ||
|
||
cameraBox2D = worldCamera.combined.cpy(); | ||
cameraBox2D.scl(WORLD_TO_RENDER); | ||
} | ||
|
||
public OrthographicCamera getWorld() { | ||
return worldCamera; | ||
} | ||
|
||
public OrthographicCamera getLight() { | ||
return lightCamera; | ||
} | ||
|
||
public Matrix4 getDebug() { | ||
return cameraBox2D; | ||
} | ||
|
||
public float WORLD_TO_RENDER() { | ||
return WORLD_TO_RENDER; | ||
} | ||
|
||
public float RENDER_TO_WORLD() { | ||
return RENDER_TO_WORLD; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters