diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2015-01-05 11:01:23 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2015-01-05 11:01:23 +0100 |
commit | c5baa5d4a12b4b5e65aa8514a2eb785d9ca398c2 (patch) | |
tree | 646481985f50a1afa11b1d7bb15294572e6e1968 /core/src/ch/asynk | |
parent | 1fb1dfb1044fca8e7a1b357792a46cea2fca9131 (diff) | |
download | RustAndDust-c5baa5d4a12b4b5e65aa8514a2eb785d9ca398c2.zip RustAndDust-c5baa5d4a12b4b5e65aa8514a2eb785d9ca398c2.tar.gz |
MenuBgCamera -> MenuCamera manage ui too
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r-- | core/src/ch/asynk/tankontank/screens/MenuCamera.java (renamed from core/src/ch/asynk/tankontank/screens/MenuBgCamera.java) | 29 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/screens/MenuScreen.java | 20 |
2 files changed, 35 insertions, 14 deletions
diff --git a/core/src/ch/asynk/tankontank/screens/MenuBgCamera.java b/core/src/ch/asynk/tankontank/screens/MenuCamera.java index 200e5ed..21f5a48 100644 --- a/core/src/ch/asynk/tankontank/screens/MenuBgCamera.java +++ b/core/src/ch/asynk/tankontank/screens/MenuCamera.java @@ -2,17 +2,20 @@ package ch.asynk.tankontank.screens; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.math.Vector3; +import com.badlogic.gdx.math.Matrix4; import com.badlogic.gdx.math.Rectangle; -public class MenuBgCamera extends OrthographicCamera +public class MenuCamera extends OrthographicCamera { private static final float ZEROF = 0.01f; private float virtualAspect; private final Rectangle virtual; private final Rectangle screen; + private final OrthographicCamera uiCamera; - public MenuBgCamera(int cx, int cy, int width, int height) + public MenuCamera(int cx, int cy, int width, int height) { super(width, height); this.virtual = new Rectangle(); @@ -21,6 +24,7 @@ public class MenuBgCamera extends OrthographicCamera this.screen = new Rectangle(); this.screen.set(0, 0, 0, 0); this.position.set(virtual.x, virtual.y, 0f); + this.uiCamera = new OrthographicCamera(); } public void updateViewport(int screenWidth, int screenHeight) @@ -42,5 +46,26 @@ public class MenuBgCamera extends OrthographicCamera Gdx.gl.glViewport((int)screen.x, (int)screen.y, (int)screen.width, (int)screen.height); update(true); + uiCamera.setToOrtho(false, screenWidth, screenHeight); + } + + public float getScreenWidth() + { + return screen.width; + } + + public float getScreenHeight() + { + return screen.height; + } + + public Vector3 uiUnproject(Vector3 v) + { + return uiCamera.unproject(v); + } + + public Matrix4 uiCombined() + { + return uiCamera.combined; } } diff --git a/core/src/ch/asynk/tankontank/screens/MenuScreen.java b/core/src/ch/asynk/tankontank/screens/MenuScreen.java index 94eb700..9c2febd 100644 --- a/core/src/ch/asynk/tankontank/screens/MenuScreen.java +++ b/core/src/ch/asynk/tankontank/screens/MenuScreen.java @@ -11,7 +11,6 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Interpolation; -import com.badlogic.gdx.utils.viewport.ScreenViewport; import ch.asynk.tankontank.TankOnTank; import ch.asynk.tankontank.ui.Position; @@ -56,8 +55,7 @@ public class MenuScreen implements Screen private ScenariosMenu scenariosMenu; private TutorialsMenu tutorialsMenu; - private final MenuBgCamera bgCamera; - private final ScreenViewport screenViewport; + private final MenuCamera camera; private final SpriteBatch batch; private Vector3 touch = new Vector3(); @@ -69,8 +67,7 @@ public class MenuScreen implements Screen float width = Gdx.graphics.getWidth(); float height = Gdx.graphics.getHeight(); - this.bgCamera = new MenuBgCamera(V_CENTER_X, V_CENTER_Y, V_WIDTH, V_HEIGHT); - this.screenViewport = new ScreenViewport(); + this.camera = new MenuCamera(V_CENTER_X, V_CENTER_Y, V_WIDTH, V_HEIGHT); this.gameAssetsLoading = false; @@ -97,7 +94,7 @@ public class MenuScreen implements Screen public boolean touchDown(int x, int y, int pointer, int button) { touch.set(x, y, 0f); - screenViewport.getCamera().unproject(touch); + camera.uiUnproject(touch); return hit(touch.x, touch.y); } }); @@ -176,7 +173,7 @@ public class MenuScreen implements Screen Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - batch.setProjectionMatrix(bgCamera.combined); + batch.setProjectionMatrix(camera.combined); batch.begin(); batch.draw(bg, 0, 0); from.draw(batch); @@ -188,10 +185,10 @@ public class MenuScreen implements Screen drawCentered(batch, unit, (int) (x + dx), (int) (y + dy)); batch.end(); - batch.setProjectionMatrix(screenViewport.getCamera().combined); + batch.setProjectionMatrix(camera.uiCombined()); batch.begin(); - batch.draw(logo, OFFSET, (screenViewport.getScreenHeight() - logo.getRegionHeight() - OFFSET)); - batch.draw(lnl, (screenViewport.getScreenWidth() - lnl.getRegionWidth() - (2 * OFFSET)), (2 * OFFSET)); + batch.draw(logo, OFFSET, (camera.getScreenHeight() - logo.getRegionHeight() - OFFSET)); + batch.draw(lnl, (camera.getScreenWidth() - lnl.getRegionWidth() - (2 * OFFSET)), (2 * OFFSET)); mainMenu.draw(batch); optionsMenu.draw(batch); scenariosMenu.draw(batch); @@ -211,8 +208,7 @@ public class MenuScreen implements Screen private void update(int width, int height) { - bgCamera.updateViewport(width, height); - screenViewport.update(width, height, true); + camera.updateViewport(width, height); Position.update(width, height); setCenteredPosition(from, xPath[0], yPath[0]); |