From ecaf86a57adb6bc40e24e483d9e41b37dfbecf6d Mon Sep 17 00:00:00 2001 From: Matt Low Date: Thu, 2 Jan 2020 20:51:50 +0400 Subject: [PATCH] Cache assets --- core/src/com/me/pacman/Assets.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/core/src/com/me/pacman/Assets.java b/core/src/com/me/pacman/Assets.java index fb985c3..2b9f6e0 100644 --- a/core/src/com/me/pacman/Assets.java +++ b/core/src/com/me/pacman/Assets.java @@ -15,6 +15,10 @@ public class Assets { private AssetManager manager; + private Texture levelBackground; + private Texture levelWinBackground; + private Texture menuBackground; + public TextureRegion[][] level; public TextureRegion[][] deathAnimation; public TextureRegion[][] ghosts; @@ -31,6 +35,7 @@ public class Assets { public Sound return_base; public Sound siren, siren_fast, siren_faster, siren_fastest; + private BitmapFont font; public Assets() { this.manager = new AssetManager(); @@ -77,6 +82,11 @@ public class Assets { // finish loading assets from disk manager.finishLoading(); + this.font = manager.get("fonts/joystix.ttf", BitmapFont.class); + levelBackground = manager.get("level_background.png", Texture.class); + levelWinBackground = manager.get("level_background_win.png", Texture.class); + menuBackground = manager.get("menu_background.png", Texture.class); + // cache our texture regions level = TextureRegion.split(manager.get("sprites/level.png", Texture.class), 8, 8); deathAnimation = TextureRegion.split(manager.get("sprites/death.png", Texture.class), 16, 16); @@ -103,15 +113,15 @@ public class Assets { } public Texture getLevelBackground() { - return manager.get("level_background.png", Texture.class); + return levelBackground; } public Texture getLevelWinBackground() { - return manager.get("level_background_win.png", Texture.class); + return levelWinBackground; } public Texture getMenuBackground() { - return manager.get("menu_background.png", Texture.class); + return menuBackground; } public Texture getLogo() { @@ -119,7 +129,7 @@ public class Assets { } public BitmapFont getFont() { - return manager.get("fonts/joystix.ttf", BitmapFont.class); + return font; } public void dispose() {