Class GameView
- java.lang.Object
-
- com.bombinggames.wurfelengine.core.GameView
-
- All Implemented Interfaces:
GameManager
- Direct Known Subclasses:
EditorView
,GameViewWithCamera
public class GameView extends java.lang.Object implements GameManager
The GameView manages everything what should be drawn in an active game in game space. It includes two batches. One for gamespace and one for projection space.
Code which needs a running instance should be put into theinit(com.bombinggames.wurfelengine.core.Controller, com.bombinggames.wurfelengine.core.GameView)
method.
-
-
Constructor Summary
Constructors Constructor Description GameView()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCamera(Camera camera)
Add a camera to the game.static void
classInit()
Shoud be called before the object get initialized.void
dispose()
should be called if removed from memoryvoid
drawString(java.lang.String msg, int xPos, int yPos, com.badlogic.gdx.graphics.Color color)
Draw a string in a color.void
drawString(java.lang.String msg, int xPos, int yPos, com.badlogic.gdx.graphics.Color color, boolean openbatch)
Draw a string in a color.void
enter()
Should be called when the manager becomes active.void
exit()
Should get called when you leave the editor.java.util.ArrayList<Camera>
getCameras()
Returns a camera.Controller
getController()
float
getEqualizationScale()
The equalizationScale is a factor which scales the GUI/HUD to have the same relative size with different resolutions.SpriteBatchWithZAxis
getGameSpaceSpriteBatch()
Game view dependent spriteBatchLoadMenu
getLoadMenu()
Get a menu which can be used for loading maps.com.badlogic.gdx.graphics.g2d.SpriteBatch
getProjectionSpaceSpriteBatch()
Get the value of projectionSpaceSpriteBatchRenderStorage
getRenderStorage()
com.badlogic.gdx.graphics.glutils.ShaderProgram
getShader()
Get the loaded shader program of the view.com.badlogic.gdx.graphics.glutils.ShapeRenderer
getShapeRenderer()
to render in screen space with view space scaling?com.badlogic.gdx.scenes.scene2d.Stage
getStage()
The libGDX scene2d stagevoid
init(Controller controller, GameView oldView)
Loades some files and set up everything when the engine is running.boolean
isInitalized()
boolean
isUsingDefaultShader()
void
loadShaders()
reloads the shadersvoid
onEnter()
Override to specify what should happen when the mangager becomes active.void
preUpdate(float dt)
update before the game logic callsvoid
render()
Main method which is called every time and renders everything.void
resetProjectionMatrix()
sets matrix to render in screen space coordinatesvoid
resize(int width, int height)
should be called when the window get resizedIntersection
screenToGame(int x, int y)
Returns the approximated game position belonging to a point on the screen.Point
screenToGameBasic(int x, int y)
Returns matching point on the ground.float
screenXtoView(int screenX, Camera camera)
Reverts the perspective and transforms it into a coordiante which can be used in the game logic.float
screenYtoView(int screenY, Camera camera)
Reverts the projection and transforms it into game space.void
setRenderStorage(RenderStorage renderstorage)
void
setShader(com.badlogic.gdx.graphics.glutils.ShaderProgram shader)
void
update(float dt)
Updates every camera and everything else which must be updated.void
useDefaultShader()
int
viewToScreenX(int x, Camera camera)
Not a homomorphism, which means f(a*b) !int
viewToScreenY(int y, Camera camera)
Not a homomorphism, which means f(a*b) !
-
-
-
Method Detail
-
classInit
public static void classInit()
Shoud be called before the object get initialized. Initializes class fields.
-
init
public void init(Controller controller, GameView oldView)
Loades some files and set up everything when the engine is running. After this has been inactive useonEnter()
This method is a an implementation of the Setter Injection pattern.- Parameters:
controller
- The dependent data controller used for the view. Can be null but should not.oldView
- The view used before. Can be null.- See Also:
onEnter()
-
getShader
public com.badlogic.gdx.graphics.glutils.ShaderProgram getShader()
Get the loaded shader program of the view.- Returns:
-
loadShaders
public void loadShaders()
reloads the shaders
-
onEnter
public void onEnter()
Description copied from interface:GameManager
Override to specify what should happen when the mangager becomes active. Super call must not be implemented.- Specified by:
onEnter
in interfaceGameManager
-
enter
public final void enter()
Description copied from interface:GameManager
Should be called when the manager becomes active. CallsGameManager.onEnter()
.- Specified by:
enter
in interfaceGameManager
- See Also:
GameManager.onEnter()
-
preUpdate
public void preUpdate(float dt)
update before the game logic calls- Parameters:
dt
-
-
update
public void update(float dt)
Updates every camera and everything else which must be updated.- Parameters:
dt
- time since last update in ms.
-
getRenderStorage
public RenderStorage getRenderStorage()
- Returns:
-
setRenderStorage
public void setRenderStorage(RenderStorage renderstorage)
- Parameters:
renderstorage
-
-
render
public void render()
Main method which is called every time and renders everything. You must manually render the devtools e.g. in an extended render method.
-
resetProjectionMatrix
public void resetProjectionMatrix()
sets matrix to render in screen space coordinates
-
getEqualizationScale
public float getEqualizationScale()
The equalizationScale is a factor which scales the GUI/HUD to have the same relative size with different resolutions.- Returns:
- the scale factor
-
screenXtoView
public float screenXtoView(int screenX, Camera camera)
Reverts the perspective and transforms it into a coordiante which can be used in the game logic. Should be verified if returning correct results.- Parameters:
screenX
- the x position on the screencamera
- the camera where the position is on- Returns:
- view coordinate
-
screenYtoView
public float screenYtoView(int screenY, Camera camera)
Reverts the projection and transforms it into game space. Should be verified if returning correct results.- Parameters:
screenY
- the y position on the screen. y-upcamera
- the camera where the position is on- Returns:
- view coordinate
-
screenToGameBasic
public Point screenToGameBasic(int x, int y)
Returns matching point on the ground. Can be used in game space but then its on the floor layer.- Parameters:
x
- screen spacey
- screen space. y-up- Returns:
- the position on the map. deepest layer. If no camera returns map center.
-
screenToGame
public Intersection screenToGame(int x, int y)
Returns the approximated game position belonging to a point on the screen. Does raytracing to find the intersection. Because information is lost if you do game to screen reverting this can only be done by approximating what happens in view -> game. First does screen -> view and then via raytracing view -> game.- Parameters:
x
- the x position on the screen from lefty
- the y position on the screen from bottom- Returns:
- the position on the map. can return null if no camera available
-
viewToScreenX
public int viewToScreenX(int x, Camera camera)
Not a homomorphism, which means f(a*b) != f(a)*f(b)- Parameters:
x
- view spacecamera
-- Returns:
- screen space
-
viewToScreenY
public int viewToScreenY(int y, Camera camera)
Not a homomorphism, which means f(a*b) != f(a)*f(b)- Parameters:
y
- view spacecamera
-- Returns:
- screen space
-
drawString
public void drawString(java.lang.String msg, int xPos, int yPos, com.badlogic.gdx.graphics.Color color, boolean openbatch)
Draw a string in a color.- Parameters:
msg
-xPos
- screen spaceyPos
- screen spacecolor
-openbatch
- true if begin/end shoould be called
-
drawString
public void drawString(java.lang.String msg, int xPos, int yPos, com.badlogic.gdx.graphics.Color color)
Draw a string in a color. Using open batch.- Parameters:
msg
-xPos
- screen spaceyPos
- screen spacecolor
-
-
getShapeRenderer
public com.badlogic.gdx.graphics.glutils.ShapeRenderer getShapeRenderer()
to render in screen space with view space scaling?- Returns:
-
getController
public Controller getController()
- Returns:
-
getCameras
public java.util.ArrayList<Camera> getCameras()
Returns a camera. The first camera is handled as the main camera.- Returns:
- The virtual cameras rendering the scene
-
getLoadMenu
public LoadMenu getLoadMenu()
Get a menu which can be used for loading maps.- Returns:
-
addCamera
public void addCamera(Camera camera)
Add a camera to the game. Adds this camera to the usedRenderStorage
.- Parameters:
camera
-
-
resize
public void resize(int width, int height)
should be called when the window get resized- Parameters:
width
-height
-
-
getStage
public com.badlogic.gdx.scenes.scene2d.Stage getStage()
The libGDX scene2d stage- Returns:
-
getGameSpaceSpriteBatch
public SpriteBatchWithZAxis getGameSpaceSpriteBatch()
Game view dependent spriteBatch- Returns:
-
getProjectionSpaceSpriteBatch
public com.badlogic.gdx.graphics.g2d.SpriteBatch getProjectionSpaceSpriteBatch()
Get the value of projectionSpaceSpriteBatch- Returns:
- the value of projectionSpaceSpriteBatch
-
isInitalized
public boolean isInitalized()
- Specified by:
isInitalized
in interfaceGameManager
- Returns:
-
useDefaultShader
public void useDefaultShader()
-
isUsingDefaultShader
public boolean isUsingDefaultShader()
- Returns:
-
setShader
public void setShader(com.badlogic.gdx.graphics.glutils.ShaderProgram shader)
- Parameters:
shader
-
-
exit
public void exit()
Description copied from interface:GameManager
Should get called when you leave the editor. To extend this method you should overwrite adn call super ethod.- Specified by:
exit
in interfaceGameManager
-
dispose
public void dispose()
Description copied from interface:GameManager
should be called if removed from memory- Specified by:
dispose
in interfaceGameManager
-
-