fixed memory leaks

This commit is contained in:
Sem van der Hoeven
2020-06-06 16:19:36 +02:00
parent ab3d57bc7f
commit 95a582b91e
2 changed files with 17 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ package netwerkprog.game.client;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Files;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
@@ -45,9 +46,9 @@ public class MainGame extends ApplicationAdapter {
private GAMESTATE gamestate;
private Faction chosenFaction;
private Map map;
public MapRenderer mapRenderer;
public AssetManager assets;
private static MainGame INSTANCE;
@@ -72,6 +73,7 @@ public class MainGame extends ApplicationAdapter {
textRenderer = new TextRenderer();
font = new BitmapFont();
layout = new GlyphLayout();
assets = new AssetManager();
String[] strings = new String[]{
"#########################",
@@ -107,7 +109,9 @@ public class MainGame extends ApplicationAdapter {
}
public void initCharacters() {
Texture texture = new Texture(Gdx.files.internal("core/assets/characters.png"));
assets.load("core/assets/characters.png",Texture.class);
assets.finishLoading();
Texture texture = assets.get("core/assets/characters.png");
TextureRegion[][] characters = TextureRegion.split(texture, 32, 32);
this.team = new Team();
@@ -216,6 +220,7 @@ public class MainGame extends ApplicationAdapter {
public void dispose() {
batch.dispose();
textRenderer.dispose();
assets.dispose();
}
public float getScreenWidth() {

View File

@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.utils.Disposable;
import netwerkprog.game.client.MainGame;
import netwerkprog.game.util.game.GameCharacter;
import netwerkprog.game.util.graphics.Renderable;
@@ -57,8 +58,6 @@ public class MapRenderer implements Renderable {
this.camera = camera;
this.mainGame = MainGame.getInstance();
font = new BitmapFont();
square = new Texture(Gdx.files.internal("square.png"));
square2 = new Texture(Gdx.files.internal("square2.png"));
makeTiles();
}
@@ -66,7 +65,14 @@ public class MapRenderer implements Renderable {
* loads all the images for the tiles and adds all the tiles to the array
*/
private void makeTiles() {
Texture texture = new Texture(Gdx.files.internal(tilePath));
mainGame.assets.load("square.png", Texture.class);
mainGame.assets.load("square2.png", Texture.class);
mainGame.assets.load(tilePath, Texture.class);
mainGame.assets.finishLoading();
square = mainGame.assets.get("square.png");
square2 = mainGame.assets.get("square2.png");
Texture texture = mainGame.assets.get(tilePath);
TextureRegion[][] tileTextures = TextureRegion.split(texture, 32, 32);
FLOOR_TILE = tileTextures[1][6];
@@ -196,4 +202,5 @@ public class MapRenderer implements Renderable {
public List<GameTile> getSurroundedTilesOfCurrentCharacter() {
return surroundedTilesOfCurrentCharacter;
}
}