diff --git a/core/src/cz/nic/tablexia/game/games/night_watch/NightWatchGame.java b/core/src/cz/nic/tablexia/game/games/night_watch/NightWatchGame.java index 7c447a8dd1a4f3aa8ae62fe442334f70ee0cbc2a..39282501e11403c186df440d1c617703c4029618 100644 --- a/core/src/cz/nic/tablexia/game/games/night_watch/NightWatchGame.java +++ b/core/src/cz/nic/tablexia/game/games/night_watch/NightWatchGame.java @@ -54,6 +54,8 @@ public class NightWatchGame extends AbstractTablexiaGame<GameRule> { private Map<Integer,List<Solution>> gameSolutions; private Watch watch; private TablexiaButton button; + private TextureRegion clickmap; + private Pixmap pixmap; @Override protected void gameLoaded() { @@ -70,11 +72,17 @@ public class NightWatchGame extends AbstractTablexiaGame<GameRule> { prepareWindows(); prepareWatch(); prepareButton(); + prepareClickMap(); startRound(); } + @Override + protected void screenDisposed() { + pixmap.dispose(); + } + private void prepareBackground(){ backgroundStack = new Stack(); backgroundStack.setSize(SCREEN_WIDTH, SCREEN_MIN_HEIGHT); @@ -136,6 +144,14 @@ public class NightWatchGame extends AbstractTablexiaGame<GameRule> { } + private void prepareClickMap() { + clickmap = getScreenTextureRegion(TextureHelper.getClickMapPath(difficulty)); + if (!clickmap.getTexture().getTextureData().isPrepared()) { + clickmap.getTexture().getTextureData().prepare(); + } + pixmap = clickmap.getTexture().getTextureData().consumePixmap(); + } + //initial animation private void startRound(){ enableClickables(false); @@ -301,12 +317,6 @@ public class NightWatchGame extends AbstractTablexiaGame<GameRule> { } private Color getTouchedColor(float x, float y) { - TextureRegion clickmap = getScreenTextureRegion(TextureHelper.getClickMapPath(difficulty)); - if (!clickmap.getTexture().getTextureData().isPrepared()) { - clickmap.getTexture().getTextureData().prepare(); - } - - Pixmap pixmap = clickmap.getTexture().getTextureData().consumePixmap(); int clickX = (int) (x / SCREEN_WIDTH * clickmap.getRegionWidth()); int clickY = clickmap.getRegionHeight() - (int) (y / SCREEN_MIN_HEIGHT * clickmap.getRegionHeight()); return new Color(pixmap.getPixel(clickmap.getRegionX() + clickX, clickmap.getRegionY() + clickY)); diff --git a/core/src/cz/nic/tablexia/screen/createuser/PanoramaScreen.java b/core/src/cz/nic/tablexia/screen/createuser/PanoramaScreen.java index cddcdd324b377ef03e58c16cc9b3c18cc5cad11c..888b4d98327f8f8dd17f97cf91642707e03ee2a7 100644 --- a/core/src/cz/nic/tablexia/screen/createuser/PanoramaScreen.java +++ b/core/src/cz/nic/tablexia/screen/createuser/PanoramaScreen.java @@ -51,6 +51,9 @@ public class PanoramaScreen extends AbstractTablexiaScreen<Void> { public static final String MUSIC_3 = MFX_PATH + "newspaper/3.mp3"; public static final String MUSIC_4 = MFX_PATH + "newspaper/4.mp3"; + private TextureRegion clickmap; + private Pixmap pixmap; + @Override protected String prepareScreenTextResourcesAssetName() { // no text loading @@ -60,6 +63,17 @@ public class PanoramaScreen extends AbstractTablexiaScreen<Void> { @Override protected void screenLoaded() { switchSubscreen(prepareBalcony()); + + clickmap = getScreenTextureRegion(GFX_PATH + "newspaper/clickmap"); + if (!clickmap.getTexture().getTextureData().isPrepared()) { + clickmap.getTexture().getTextureData().prepare(); + } + pixmap = clickmap.getTexture().getTextureData().consumePixmap(); + } + + @Override + protected void screenDisposed() { + pixmap.dispose(); } @Override @@ -349,12 +363,6 @@ public class PanoramaScreen extends AbstractTablexiaScreen<Void> { private Color getTouchedColor(float x, float y) { - TextureRegion clickmap = getScreenTextureRegion(GFX_PATH + "newspaper/clickmap"); - if (!clickmap.getTexture().getTextureData().isPrepared()) { - clickmap.getTexture().getTextureData().prepare(); - } - - Pixmap pixmap = clickmap.getTexture().getTextureData().consumePixmap(); int clickX = (int) (x / newspaper.getWidth() * clickmap.getRegionWidth()); int clickY = clickmap.getRegionHeight() - (int) (y / newspaper.getHeight() * clickmap.getRegionHeight()); return new Color(pixmap.getPixel(clickmap.getRegionX() + clickX, clickmap.getRegionY() + clickY)); diff --git a/core/src/cz/nic/tablexia/screen/gamemenu/GameMenuScreen.java b/core/src/cz/nic/tablexia/screen/gamemenu/GameMenuScreen.java index 13d105719c736bba253ae2e5abc93d4e8d85965a..611caf40acf51e069245bf193c9d38e9f79f9aac 100644 --- a/core/src/cz/nic/tablexia/screen/gamemenu/GameMenuScreen.java +++ b/core/src/cz/nic/tablexia/screen/gamemenu/GameMenuScreen.java @@ -16,6 +16,7 @@ import cz.nic.tablexia.util.ui.ViewPager; public class GameMenuScreen extends AbstractTablexiaScreen<Void> { private ViewPager vp; + private OfficeMenuPage officeMenuPage; @Override protected String prepareScreenTextResourcesAssetName() { @@ -27,7 +28,8 @@ public class GameMenuScreen extends AbstractTablexiaScreen<Void> { protected void screenLoaded() { getStage().setDebugAll(TablexiaSettings.getInstance().isShowBoundingBoxes()); vp = new ViewPager(); - vp.addPage(new OfficeMenuPage(this)); + officeMenuPage = new OfficeMenuPage(this); + vp.addPage(officeMenuPage); for (GameDefinition gd : GameDefinition.getActiveGames()) { vp.addPage(new GameMenuPage(this, gd)); @@ -49,4 +51,8 @@ public class GameMenuScreen extends AbstractTablexiaScreen<Void> { vp.scrollToPage(1); } + @Override + protected void screenDisposed() { + officeMenuPage.dispose(); + } } diff --git a/core/src/cz/nic/tablexia/screen/gamemenu/pages/MenuPage.java b/core/src/cz/nic/tablexia/screen/gamemenu/pages/MenuPage.java index b00985334a213070b600ce10ac26199bf07632da..540fbad7b4f6574b58a881a08e863e5593d8bb0a 100644 --- a/core/src/cz/nic/tablexia/screen/gamemenu/pages/MenuPage.java +++ b/core/src/cz/nic/tablexia/screen/gamemenu/pages/MenuPage.java @@ -2,13 +2,14 @@ package cz.nic.tablexia.screen.gamemenu.pages; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Group; +import com.badlogic.gdx.utils.Disposable; import cz.nic.tablexia.screen.AbstractTablexiaScreen; /** * Created by lhoracek on 3/4/15. */ -public abstract class MenuPage extends Group { +public abstract class MenuPage extends Group implements Disposable { private AbstractTablexiaScreen screen; public MenuPage(AbstractTablexiaScreen screen) { @@ -26,4 +27,9 @@ public abstract class MenuPage extends Group { a.setDebug(enabled); } } + + @Override + public void dispose() { + // nothing needed + } } diff --git a/core/src/cz/nic/tablexia/screen/gamemenu/pages/OfficeMenuPage.java b/core/src/cz/nic/tablexia/screen/gamemenu/pages/OfficeMenuPage.java index e2e228e06120d8dba1dd410093b2f1d05b6f2f0f..5c97a921ef86b0a588a78168d81118d70516908c 100644 --- a/core/src/cz/nic/tablexia/screen/gamemenu/pages/OfficeMenuPage.java +++ b/core/src/cz/nic/tablexia/screen/gamemenu/pages/OfficeMenuPage.java @@ -40,6 +40,8 @@ public class OfficeMenuPage extends MenuPage { private Image encyclopedia; private Image street; private Image profile; + private final Pixmap pixmap; + private final TextureRegion clickmap; public OfficeMenuPage(AbstractTablexiaScreen screen) { @@ -100,6 +102,13 @@ public class OfficeMenuPage extends MenuPage { hideAllActions(); } }); + + clickmap = getScreen().getScreenTextureRegion(GameMenuAssets.OFFICE_CLICKMAP); + if (!clickmap.getTexture().getTextureData().isPrepared()) { + clickmap.getTexture().getTextureData().prepare(); + } + + pixmap = clickmap.getTexture().getTextureData().consumePixmap(); } private void createImageStack() { @@ -149,12 +158,6 @@ public class OfficeMenuPage extends MenuPage { } private Color getTouchedColor(float x, float y) { - TextureRegion clickmap = getScreen().getScreenTextureRegion(GameMenuAssets.OFFICE_CLICKMAP); - if (!clickmap.getTexture().getTextureData().isPrepared()) { - clickmap.getTexture().getTextureData().prepare(); - } - - Pixmap pixmap = clickmap.getTexture().getTextureData().consumePixmap(); int clickX = (int) (x / getWidth() * clickmap.getRegionWidth()); int clickY = clickmap.getRegionHeight() - (int) (y / getHeight() * clickmap.getRegionHeight()); return new Color(pixmap.getPixel(clickmap.getRegionX() + clickX, clickmap.getRegionY() + clickY)); @@ -165,4 +168,9 @@ public class OfficeMenuPage extends MenuPage { */ public static class ShowStreetEvent implements ApplicationBus.ApplicationEvent { } + + @Override + public void dispose() { + pixmap.dispose(); + } }