fix: correction du viewport et ajout camera pour resolution adaptée.

This commit is contained in:
Nicolas Hordé 2015-06-18 01:48:19 +02:00
parent 89523367b9
commit c1057f706d
4 changed files with 21 additions and 14 deletions

View File

@ -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();

View File

@ -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);

View File

@ -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);
}

View File

@ -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();