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 voidaddCamera(Camera camera)Add a camera to the game.static voidclassInit()Shoud be called before the object get initialized.voiddispose()should be called if removed from memoryvoiddrawString(java.lang.String msg, int xPos, int yPos, com.badlogic.gdx.graphics.Color color)Draw a string in a color.voiddrawString(java.lang.String msg, int xPos, int yPos, com.badlogic.gdx.graphics.Color color, boolean openbatch)Draw a string in a color.voidenter()Should be called when the manager becomes active.voidexit()Should get called when you leave the editor.java.util.ArrayList<Camera>getCameras()Returns a camera.ControllergetController()floatgetEqualizationScale()The equalizationScale is a factor which scales the GUI/HUD to have the same relative size with different resolutions.SpriteBatchWithZAxisgetGameSpaceSpriteBatch()Game view dependent spriteBatchLoadMenugetLoadMenu()Get a menu which can be used for loading maps.com.badlogic.gdx.graphics.g2d.SpriteBatchgetProjectionSpaceSpriteBatch()Get the value of projectionSpaceSpriteBatchRenderStoragegetRenderStorage()com.badlogic.gdx.graphics.glutils.ShaderProgramgetShader()Get the loaded shader program of the view.com.badlogic.gdx.graphics.glutils.ShapeRenderergetShapeRenderer()to render in screen space with view space scaling?com.badlogic.gdx.scenes.scene2d.StagegetStage()The libGDX scene2d stagevoidinit(Controller controller, GameView oldView)Loades some files and set up everything when the engine is running.booleanisInitalized()booleanisUsingDefaultShader()voidloadShaders()reloads the shadersvoidonEnter()Override to specify what should happen when the mangager becomes active.voidpreUpdate(float dt)update before the game logic callsvoidrender()Main method which is called every time and renders everything.voidresetProjectionMatrix()sets matrix to render in screen space coordinatesvoidresize(int width, int height)should be called when the window get resizedIntersectionscreenToGame(int x, int y)Returns the approximated game position belonging to a point on the screen.PointscreenToGameBasic(int x, int y)Returns matching point on the ground.floatscreenXtoView(int screenX, Camera camera)Reverts the perspective and transforms it into a coordiante which can be used in the game logic.floatscreenYtoView(int screenY, Camera camera)Reverts the projection and transforms it into game space.voidsetRenderStorage(RenderStorage renderstorage)voidsetShader(com.badlogic.gdx.graphics.glutils.ShaderProgram shader)voidupdate(float dt)Updates every camera and everything else which must be updated.voiduseDefaultShader()intviewToScreenX(int x, Camera camera)Not a homomorphism, which means f(a*b) !intviewToScreenY(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:GameManagerOverride to specify what should happen when the mangager becomes active. Super call must not be implemented.- Specified by:
onEnterin interfaceGameManager
-
enter
public final void enter()
Description copied from interface:GameManagerShould be called when the manager becomes active. CallsGameManager.onEnter().- Specified by:
enterin 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:
isInitalizedin 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:GameManagerShould get called when you leave the editor. To extend this method you should overwrite adn call super ethod.- Specified by:
exitin interfaceGameManager
-
dispose
public void dispose()
Description copied from interface:GameManagershould be called if removed from memory- Specified by:
disposein interfaceGameManager
-
-