feat: ajout d'un asset manager ecran de chargement avec jauge amélioration de l'algorithme de coloration des textures traitement simultané du chargement et de la coloration son en streaming, ok sur android.

This commit is contained in:
Nicolas Hordé 2015-06-20 17:04:11 +02:00
parent a235c5241c
commit 051bce8973
3 changed files with 67 additions and 25 deletions

View File

@ -2,6 +2,9 @@ package fr.evolving.assets;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences; import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.assets.loaders.SkinLoader;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Camera; import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
@ -13,6 +16,7 @@ import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.TextureData; import com.badlogic.gdx.graphics.TextureData;
import com.badlogic.gdx.graphics.g2d.Animation; import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion; import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.Texture.TextureWrap; import com.badlogic.gdx.graphics.Texture.TextureWrap;
@ -28,7 +32,7 @@ public class AssetLoader {
public static Texture Texture_fond; public static Texture Texture_fond;
public static Texture Texture_fond2; public static Texture Texture_fond2;
public static Texture Texture_logo; public static Texture Texture_logo;
public static Sound intro; public static Music intro;
public static int width; public static int width;
public static Color[] Levelcolors; public static Color[] Levelcolors;
public static Color[] Typecolors; public static Color[] Typecolors;
@ -39,37 +43,51 @@ public class AssetLoader {
public static Preferences prefs; public static Preferences prefs;
public static ScalingViewport viewport; public static ScalingViewport viewport;
public static OrthographicCamera Camera; public static OrthographicCamera Camera;
private static Texture emptyT;
private static Texture fullT;
public static NinePatch empty;
public static NinePatch full;
public static AssetManager manager;
public static void addstyle(TextureAtlas Atlas_level,String Name) { public static void addstyle(TextureAtlas Atlas_level,String Name) {
AtlasRegion AnAtlasRegion = Atlas_level.findRegion(Name); AtlasRegion AnAtlasRegion = Atlas_level.findRegion(Name);
if (AnAtlasRegion==null) return; if (AnAtlasRegion==null) return;
TextureData ATextureData = AnAtlasRegion.getTexture().getTextureData(); TextureData ATextureData = AnAtlasRegion.getTexture().getTextureData();
ATextureData.prepare(); ATextureData.prepare();
Pixmap Pixmap_Over=ATextureData.consumePixmap(); Pixmap Pixmap_Ori=ATextureData.consumePixmap();
Pixmap Pixmap_Disable=new Pixmap(Pixmap_Over.getWidth(), Pixmap_Over.getHeight(), Pixmap.Format.RGBA8888); Pixmap Pixmap_Over=new Pixmap(AnAtlasRegion.getRegionWidth(), AnAtlasRegion.getRegionHeight(), Pixmap.Format.RGBA8888);
Pixmap Pixmap_Down=new Pixmap(Pixmap_Over.getWidth(), Pixmap_Over.getHeight(), Pixmap.Format.RGBA8888); Pixmap Pixmap_Disable=new Pixmap(AnAtlasRegion.getRegionWidth(), AnAtlasRegion.getRegionHeight(), Pixmap.Format.RGBA8888);
for(int x=0; x < Pixmap_Over.getWidth(); x++) Pixmap Pixmap_Down=new Pixmap(AnAtlasRegion.getRegionWidth(), AnAtlasRegion.getRegionHeight(), Pixmap.Format.RGBA8888);
Color acolor;
for(int x=0; x < AnAtlasRegion.getRegionWidth(); x++)
{ {
for(int y =0; y < Pixmap_Over.getHeight(); y++) for(int y =0; y < AnAtlasRegion.getRegionHeight(); y++)
{ {
Color acolor= new Color(Pixmap_Over.getPixel(x, y)); acolor= new Color(Pixmap_Ori.getPixel(AnAtlasRegion.getRegionX()+x, AnAtlasRegion.getRegionY()+y));
Pixmap_Down.drawPixel(x, y,Color.rgba8888(acolor.a,0f,0f,acolor.a)); Pixmap_Down.drawPixel(x, y,Color.rgba8888(acolor.a,0f,0f,acolor.a));
Pixmap_Disable.drawPixel(x, y, Color.rgba8888(acolor.r*0.352f,acolor.g*0.352f,acolor.b*0.352f,acolor.a)); Pixmap_Disable.drawPixel(x, y, Color.rgba8888(acolor.r*0.352f,acolor.g*0.352f,acolor.b*0.352f,acolor.a));
Pixmap_Over.drawPixel(x, y, Color.rgba8888(acolor.r,acolor.g*0.2f,acolor.b*0.2f,acolor.a)); Pixmap_Over.drawPixel(x, y, Color.rgba8888(acolor.r,acolor.g*0.2f,acolor.b*0.2f,acolor.a));
} }
} }
Atlas_level.addRegion(Name+"_disabled", new TextureRegion(new Texture(Pixmap_Disable),AnAtlasRegion.getRegionX(),AnAtlasRegion.getRegionY(),AnAtlasRegion.getRegionWidth(),AnAtlasRegion.getRegionHeight())); Atlas_level.addRegion(Name+"_disabled", new TextureRegion(new Texture(Pixmap_Disable)));
Atlas_level.addRegion(Name+"_over", new TextureRegion(new Texture(Pixmap_Over),AnAtlasRegion.getRegionX(),AnAtlasRegion.getRegionY(),AnAtlasRegion.getRegionWidth(),AnAtlasRegion.getRegionHeight())); Atlas_level.addRegion(Name+"_over", new TextureRegion(new Texture(Pixmap_Over)));
Atlas_level.addRegion(Name+"_down", new TextureRegion(new Texture(Pixmap_Down),AnAtlasRegion.getRegionX(),AnAtlasRegion.getRegionY(),AnAtlasRegion.getRegionWidth(),AnAtlasRegion.getRegionHeight())); Atlas_level.addRegion(Name+"_down", new TextureRegion(new Texture(Pixmap_Down)));
} }
public static void loadall() { public static void loadall() {
Gdx.app.debug("AssetLoader","Chargements de tout les éléments multimédia"); Gdx.app.debug("AssetLoader","Initialisation du asset manager");
Texture_fond = new Texture(Gdx.files.internal("pictures/fond.png")); manager = new AssetManager();
Texture_fond.setWrap(TextureWrap.Repeat, TextureWrap.Repeat); Gdx.app.debug("AssetLoader","Initialisation du chargement des éléments multimédia");
Texture_fond2 = new Texture(Gdx.files.internal("pictures/fond2.png")); manager.load("textures/level.pack", TextureAtlas.class);
Texture_fond2.setWrap(TextureWrap.Repeat, TextureWrap.Repeat); manager.load("pictures/fond.png", Texture.class);
Atlas_level= new TextureAtlas(Gdx.files.internal("textures/level.pack")); manager.load("pictures/fond2.png", Texture.class);
manager.load("musics/intro.mp3", Music.class);
}
public static void finishall() {
Gdx.app.debug("AssetLoader","Ajout des textures disabled,over et down");
Atlas_level = manager.get("textures/level.pack");
if (manager.isLoaded("textures/level.pack")) {
for(int i=0; i < 5; i++) for(int i=0; i < 5; i++)
addstyle(Atlas_level,"leveler"+String.valueOf(i)); addstyle(Atlas_level,"leveler"+String.valueOf(i));
addstyle(Atlas_level,"arrows"); addstyle(Atlas_level,"arrows");
@ -80,15 +98,26 @@ public class AssetLoader {
addstyle(Atlas_level,"cycle"); addstyle(Atlas_level,"cycle");
addstyle(Atlas_level,"temp"); addstyle(Atlas_level,"temp");
addstyle(Atlas_level,"nrj"); addstyle(Atlas_level,"nrj");
addstyle(Atlas_level,"rayon"); addstyle(Atlas_level,"rayon");
Skin_level = new Skin(Gdx.files.internal("textures/level.json"),Atlas_level); }
Gdx.app.debug("AssetLoader","Chargement des skins et attente fin chargement");
manager.load("textures/level.json", Skin.class, new SkinLoader.SkinParameter("textures/level.pack"));
manager.finishLoading();
Gdx.app.debug("AssetLoader","Affectation des éléments multimédia");
intro = manager.get("musics/intro.mp3");
Texture_fond = manager.get("pictures/fond.png");
Texture_fond.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
Texture_fond2 = manager.get("pictures/fond2.png");
Texture_fond2.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
Skin_level = manager.get("textures/level.json");
Skin_level.addRegions(Atlas_level);
Gdx.app.debug("AssetLoader","Definition des constantes");
Levelcolors=new Color[5]; Levelcolors=new Color[5];
Levelcolors=new Color[]{AssetLoader.Skin_level.getColor("world1"),AssetLoader.Skin_level.getColor("world2"),AssetLoader.Skin_level.getColor("world3"),AssetLoader.Skin_level.getColor("world4"),AssetLoader.Skin_level.getColor("world5")}; Levelcolors=new Color[]{AssetLoader.Skin_level.getColor("world1"),AssetLoader.Skin_level.getColor("world2"),AssetLoader.Skin_level.getColor("world3"),AssetLoader.Skin_level.getColor("world4"),AssetLoader.Skin_level.getColor("world5")};
Typecolors=new Color[13]; Typecolors=new Color[13];
Typecolors=new Color[]{new Color(0,0,1f,1),new Color(0,0.6f,0,1),new Color(0.196f,0.803f,0.196f,1),new Color(0.5f,0.5f,0.5f,1),new Color(0.8f,0.8f,0.8f,1),new Color(0.6f,0,0,1),new Color(1f,0,0,1),new Color(0,0,0.6f,1),new Color(0,0,0.6f,1),new Color(0,0,0.6f,1),new Color(0,0,0.6f,1),new Color(0.294f,0.466f,0.615f,1),new Color(0.478f,0.192f,0.098f,1)}; Typecolors=new Color[]{new Color(0,0,1f,1),new Color(0,0.6f,0,1),new Color(0.196f,0.803f,0.196f,1),new Color(0.5f,0.5f,0.5f,1),new Color(0.8f,0.8f,0.8f,1),new Color(0.6f,0,0,1),new Color(1f,0,0,1),new Color(0,0,0.6f,1),new Color(0,0,0.6f,1),new Color(0,0,0.6f,1),new Color(0,0,0.6f,1),new Color(0.294f,0.466f,0.615f,1),new Color(0.478f,0.192f,0.098f,1)};
Typenames=new String[13]; Typenames=new String[13];
Typenames=new String[]{"E-","e-","Ph","e0","E0","e+","E+","K","L","M","N","n","p"}; Typenames=new String[]{"E-","e-","Ph","e0","E0","e+","E+","K","L","M","N","n","p"};
intro = Gdx.audio.newSound(Gdx.files.internal("musics/intro.mp3"));
} }
public static int setpref() { public static int setpref() {
@ -133,6 +162,10 @@ public class AssetLoader {
Gdx.app.debug("AssetLoader","Chargements des éléments minimalistes"); Gdx.app.debug("AssetLoader","Chargements des éléments minimalistes");
Texture_logo = new Texture(Gdx.files.internal("pictures/logo.png")); Texture_logo = new Texture(Gdx.files.internal("pictures/logo.png"));
Texture_logo.setFilter(TextureFilter.Linear,TextureFilter.Linear); Texture_logo.setFilter(TextureFilter.Linear,TextureFilter.Linear);
emptyT=new Texture(Gdx.files.internal("pictures/empty.png"));
fullT=new Texture(Gdx.files.internal("pictures/full.png"));
empty=new NinePatch(new TextureRegion(emptyT,24,24),8,8,8,8);
full=new NinePatch(new TextureRegion(fullT,24,24),8,8,8,8);
} }
public static void dispose() { public static void dispose() {

View File

@ -217,7 +217,7 @@ public class LevelScreen implements Screen {
stage.addActor(Victory); stage.addActor(Victory);
Gdx.input.setInputProcessor(stage); Gdx.input.setInputProcessor(stage);
Gdx.app.debug("AssetLoader","Début dans la bande son \'intro\'"); Gdx.app.debug("AssetLoader","Début dans la bande son \'intro\'");
AssetLoader.intro.setLooping(0, true); AssetLoader.intro.setLooping(true);
AssetLoader.intro.play(); AssetLoader.intro.play();
} }

View File

@ -20,12 +20,15 @@ public class SplashScreen implements Screen {
private Stage stage; private Stage stage;
private Image splashImage; private Image splashImage;
private float scale; private float scale;
private SpriteBatch batcher;
public SplashScreen(main game) { public SplashScreen(main game) {
this.game = game;
AssetLoader.load(); AssetLoader.load();
this.game = game;
batcher= new SpriteBatch();
stage = new Stage(AssetLoader.viewport); stage = new Stage(AssetLoader.viewport);
splashImage = new Image(AssetLoader.Texture_logo); splashImage = new Image(AssetLoader.Texture_logo);
AssetLoader.loadall();
} }
@Override @Override
@ -35,14 +38,12 @@ public class SplashScreen implements Screen {
splashImage.setScale(scale); splashImage.setScale(scale);
splashImage.setPosition((AssetLoader.width / 2) - (scale * splashImage.getWidth() / 2), (AssetLoader.height / 2) - (scale * splashImage.getHeight() / 2)); splashImage.setPosition((AssetLoader.width / 2) - (scale * splashImage.getWidth() / 2), (AssetLoader.height / 2) - (scale * splashImage.getHeight() / 2));
stage.addActor(splashImage); stage.addActor(splashImage);
splashImage.addAction(Actions.sequence(Actions.alpha(0),Actions.fadeIn(0.5f),Actions.run(new Runnable() { splashImage.addAction(Actions.sequence(Actions.alpha(0),Actions.fadeIn(5f),Actions.run(new Runnable() {
//splashImage.addAction(Actions.sequence(Actions.alpha(0),Actions.run(new Runnable() {
@Override @Override
public void run() { public void run() {
AssetLoader.loadall(); AssetLoader.finishall();
} }
}),Actions.run(new Runnable() { }),Actions.run(new Runnable() {
//splashImage.addAction(Actions.sequence(Actions.alpha(0),Actions.run(new Runnable() {
@Override @Override
public void run() { public void run() {
((Game)Gdx.app.getApplicationListener()).setScreen(new LevelScreen()); ((Game)Gdx.app.getApplicationListener()).setScreen(new LevelScreen());
@ -56,6 +57,14 @@ public class SplashScreen implements Screen {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(); stage.act();
stage.draw(); stage.draw();
if (AssetLoader.manager!=null) {
batcher.begin();
batcher.setProjectionMatrix(AssetLoader.Camera.combined);
AssetLoader.empty.draw(batcher, (AssetLoader.width / 2) - 400f, 150f, 800f, 50f);
AssetLoader.full.draw(batcher, (AssetLoader.width / 2) - 400f, 150f, AssetLoader.manager.getProgress()*800f, 50f);
AssetLoader.manager.update();
batcher.end();
}
} }
@Override @Override