From c1057f706d568665425a75583ed47a00710bbed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Hord=C3=A9?= Date: Thu, 18 Jun 2015 01:48:19 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20correction=20du=20viewport=20et=20ajout?= =?UTF-8?q?=20camera=20pour=20resolution=20adapt=C3=A9e.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/fr/evolving/assets/AssetLoader.java | 8 ++++++-- core/src/fr/evolving/game/main.java | 12 ++++++------ core/src/fr/evolving/screens/SplashScreen.java | 2 +- core/src/fr/evolving/worlds/LevelRenderer.java | 13 ++++++++----- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/core/src/fr/evolving/assets/AssetLoader.java b/core/src/fr/evolving/assets/AssetLoader.java index f9c963e..17012eb 100644 --- a/core/src/fr/evolving/assets/AssetLoader.java +++ b/core/src/fr/evolving/assets/AssetLoader.java @@ -36,6 +36,7 @@ public class AssetLoader { public static boolean stretch=false; public static Preferences prefs; public static ScalingViewport viewport; + public static OrthographicCamera Camera; public static void addstyle(TextureAtlas Atlas_level,String Name) { AtlasRegion AnAtlasRegion = Atlas_level.findRegion(Name); @@ -100,12 +101,15 @@ public class AssetLoader { } else Gdx.app.debug("AssetLoader","Ratio 16/9, résolution virtuelle : 1920x1080."); + Camera = new OrthographicCamera(width,height); + Camera.position.set(width/2, height/2, 0); + Camera.update(); if (stretch) { - viewport = new StretchViewport(realWidth,realHeight); + viewport = new StretchViewport(width,height); Gdx.app.debug("AssetLoader","Adaptation d'écran maximale, 'Aspect-Ratio' non conservé."); } else { - viewport = new FitViewport(realWidth,realHeight); + viewport = new FitViewport(width,height); Gdx.app.debug("AssetLoader","Adaptation d'écran totale, 'Aspect-Ratio' conservé."); } viewport.apply(); diff --git a/core/src/fr/evolving/game/main.java b/core/src/fr/evolving/game/main.java index 3c5aab8..41bf3c2 100644 --- a/core/src/fr/evolving/game/main.java +++ b/core/src/fr/evolving/game/main.java @@ -12,8 +12,8 @@ public class main extends Game { @Override public void create() { Gdx.app.setLogLevel(AssetLoader.setpref()); - //debug(); - test(); + debug(); + //test(); Gdx.app.debug(getClass().getSimpleName(), "Récupération de la résolution des préférences."); if (AssetLoader.prefs.contains("ResolutionX") && AssetLoader.prefs.contains("ResolutionX")) { try { @@ -38,8 +38,8 @@ public class main extends Game { } public void debug() { - AssetLoader.prefs.putInteger("ResolutionX", 1280); - AssetLoader.prefs.putInteger("ResolutionY", 1024); + AssetLoader.prefs.putInteger("ResolutionX", 640); + AssetLoader.prefs.putInteger("ResolutionY", 200); AssetLoader.prefs.putBoolean("Fullscreen", false); AssetLoader.prefs.putBoolean("VSync", false); AssetLoader.prefs.putInteger("log", Gdx.app.LOG_DEBUG); @@ -48,8 +48,8 @@ public class main extends Game { } public void test() { - AssetLoader.prefs.putInteger("ResolutionX", 1280); - AssetLoader.prefs.putInteger("ResolutionY", 1024); + AssetLoader.prefs.putInteger("ResolutionX", 1920); + AssetLoader.prefs.putInteger("ResolutionY", 1080); AssetLoader.prefs.putBoolean("Fullscreen", true); AssetLoader.prefs.putBoolean("VSync", true); AssetLoader.prefs.putInteger("log", Gdx.app.LOG_INFO); diff --git a/core/src/fr/evolving/screens/SplashScreen.java b/core/src/fr/evolving/screens/SplashScreen.java index 07a1b35..80e52d2 100644 --- a/core/src/fr/evolving/screens/SplashScreen.java +++ b/core/src/fr/evolving/screens/SplashScreen.java @@ -24,7 +24,7 @@ public class SplashScreen implements Screen { public SplashScreen(main game) { this.game = game; AssetLoader.load(); - stage = new Stage(); + stage = new Stage(AssetLoader.viewport); splashImage = new Image(AssetLoader.Texture_logo); } diff --git a/core/src/fr/evolving/worlds/LevelRenderer.java b/core/src/fr/evolving/worlds/LevelRenderer.java index bc195f9..fa4ec61 100644 --- a/core/src/fr/evolving/worlds/LevelRenderer.java +++ b/core/src/fr/evolving/worlds/LevelRenderer.java @@ -41,6 +41,7 @@ public class LevelRenderer { batcher2 = new SpriteBatch(); shapeRenderer = new ShapeRenderer(); Laser=new Laser(); + AssetLoader.viewport.apply(); } public void evolve() { @@ -68,6 +69,7 @@ public class LevelRenderer { //Gdx.gl.glViewport(0, 0, AssetLoader.width, AssetLoader.height); batcher.begin(); + batcher.setProjectionMatrix(AssetLoader.Camera.combined); batcher.setColor(0.25f,0.25f,0.25f,1); batcher.draw(AssetLoader.Texture_fond2, 0, 0, this.scrollx/2, this.scrolly/2, AssetLoader.width, AssetLoader.height); batcher.setColor(0.7f,0.7f,0.7f,1); @@ -81,12 +83,13 @@ public class LevelRenderer { Gdx.gl.glEnable(GL20.GL_BLEND); shapeRenderer.begin(ShapeType.Filled); + shapeRenderer.setProjectionMatrix(AssetLoader.Camera.combined); shapeRenderer.setColor(0.5f, 0.5f, 0.5f, 0.5f); - shapeRenderer.rect(10, 10, 1114, 140); - shapeRenderer.rect(1134, 10, AssetLoader.width-1144, 140); - shapeRenderer.rect(1134, 160, AssetLoader.width-1144, 140); - shapeRenderer.rect(1134, 310, AssetLoader.width-1144, 300); - shapeRenderer.rect(1134, 620, AssetLoader.width-1144, AssetLoader.height-620); + shapeRenderer.rect(10, 10, 1500, 140); + shapeRenderer.rect(1500, 10, AssetLoader.width-1500, 140); + shapeRenderer.rect(1500, 160, AssetLoader.width-1500, 140); + shapeRenderer.rect(1500, 310, AssetLoader.width-1500, 300); + shapeRenderer.rect(1500, 620, AssetLoader.width-1500, AssetLoader.height-620); shapeRenderer.end(); batcher2.begin();