Bug 18: Separated SpriteBatch and BitmapFont

This commit is contained in:
Robert Vokac 2024-10-07 17:38:26 +02:00
parent 60e26c364a
commit 3c397e354f
Signed by: robertvokac
GPG Key ID: FB9CE8E20AADA55F
9 changed files with 64 additions and 58 deletions

View File

@ -1,10 +1,6 @@
package com.openeggbert.core.main; package com.openeggbert.core.main;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Camera; import com.badlogic.gdx.graphics.Camera;
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.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.utils.ObjectMap; import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.viewport.Viewport; import com.badlogic.gdx.utils.viewport.Viewport;
@ -18,6 +14,9 @@ import com.openeggbert.core.screen.InitScreen;
import com.openeggbert.core.utils.OpenEggbertUtils; import com.openeggbert.core.utils.OpenEggbertUtils;
import com.pixelgamelibrary.api.game.GameAdapter; import com.pixelgamelibrary.api.game.GameAdapter;
import com.pixelgamelibrary.api.Pixel; import com.pixelgamelibrary.api.Pixel;
import com.pixelgamelibrary.api.graphics.BitmapFont;
import com.pixelgamelibrary.api.graphics.SpriteBatch;
import com.pixelgamelibrary.api.graphics.Texture;
import com.pixelgamelibrary.api.storage.FileHandle; import com.pixelgamelibrary.api.storage.FileHandle;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -74,12 +73,12 @@ public class OpenEggbertGame extends GameAdapter {
// for(FileHandle f:Gdx.files.internal(".").list()) { // for(FileHandle f:Gdx.files.internal(".").list()) {
// System.out.println("assets contains also: " + f.name()); // System.out.println("assets contains also: " + f.name());
// } // }
com.pixelgamelibrary.api.storage.FileHandle embeddedModsDirectory = Pixel.files().assets().file("/embedded_mods"); com.pixelgamelibrary.api.storage.FileHandle embeddedModsDirectory = Pixel.files().assets("/embedded_mods");
System.out.println("embeddedModsDirectory.exists=" + embeddedModsDirectory.exists()); System.out.println("embeddedModsDirectory.exists=" + embeddedModsDirectory.exists());
System.out.println("embeddedModsDirectory.list().size()=" + embeddedModsDirectory.list().size()); System.out.println("embeddedModsDirectory.list().size()=" + embeddedModsDirectory.list().size());
embeddedModsDirectory.list().forEach(e -> System.out.println(e.path())); embeddedModsDirectory.list().forEach(e -> System.out.println(e.path()));
Pixel.files().assets().list().forEach(e -> System.out.println(e)); Pixel.files().assetsStorage().list().forEach(e -> System.out.println(e));
for (FileHandle embeddedModGroup : embeddedModsDirectory.list()) { for (FileHandle embeddedModGroup : embeddedModsDirectory.list()) {
if (embeddedModGroup.name().equals("README.md")) { if (embeddedModGroup.name().equals("README.md")) {
@ -109,13 +108,13 @@ public class OpenEggbertGame extends GameAdapter {
} }
//// ////
batch = new SpriteBatch(); batch = Pixel.graphics().newSpriteBatch();
//batch.setProjectionMatrix(viewport.getCamera().combined); //batch.setProjectionMatrix(viewport.getCamera().combined);
image = new Texture("libgdx.png"); image = Pixel.graphics().newTexture("libgdx.png");
shapeRenderer = new ShapeRenderer(); shapeRenderer = new ShapeRenderer();
font = new BitmapFont( font = Pixel.graphics().newBitmapFont(
Gdx.files.internal("com/badlogic/gdx/utils/lsans-15.fnt"), Gdx.files.internal("com/badlogic/gdx/utils/lsans-15.png"), Pixel.files().assets("com/badlogic/gdx/utils/lsans-15.fnt"), Pixel.files().assets("com/badlogic/gdx/utils/lsans-15.png"),
false, true false
); );
System.out.println("Going to set screen"); System.out.println("Going to set screen");
@ -134,8 +133,8 @@ public class OpenEggbertGame extends GameAdapter {
} }
} }
public void loadImageTexture(com.badlogic.gdx.files.FileHandle fileHandle) { public void loadImageTexture(FileHandle fileHandle) {
Texture texture = new Texture(fileHandle); Texture texture = Pixel.graphics().newTexture(fileHandle);
if(!fileHandle.exists()) { if(!fileHandle.exists()) {
throw new OpenEggbertException("File does not exist: " + fileHandle.path()); throw new OpenEggbertException("File does not exist: " + fileHandle.path());
} }

View File

@ -21,10 +21,11 @@ package com.openeggbert.core.screen;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter; import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.graphics.Color; import com.pixelgamelibrary.api.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.utils.ScreenUtils; import com.badlogic.gdx.utils.ScreenUtils;
import com.openeggbert.core.main.OpenEggbertGame; import com.openeggbert.core.main.OpenEggbertGame;
import com.pixelgamelibrary.api.graphics.BitmapFont;
/** /**
* *
@ -61,7 +62,7 @@ public class AbstractGameScreen extends OpenEggbertScreen {
BitmapFont font; BitmapFont font;
font = game.getFont(); font = game.getFont();
font.getData().setScale(2.0f); font.setScale(2.0f);
font.setColor(Color.RED); font.setColor(Color.RED);
font.draw(batch, "Sorry, game is not yet implemented", 40, 400); font.draw(batch, "Sorry, game is not yet implemented", 40, 400);

View File

@ -21,10 +21,11 @@ package com.openeggbert.core.screen;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter; import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.graphics.Color; import com.pixelgamelibrary.api.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.utils.ScreenUtils; import com.badlogic.gdx.utils.ScreenUtils;
import com.openeggbert.core.main.OpenEggbertGame; import com.openeggbert.core.main.OpenEggbertGame;
import com.pixelgamelibrary.api.graphics.BitmapFont;
import java.util.Optional; import java.util.Optional;
/** /**
@ -67,7 +68,7 @@ public class DemoScreen extends OpenEggbertScreen {
BitmapFont font; BitmapFont font;
font = game.getFont(); font = game.getFont();
font.getData().setScale(2.0f); font.setScale(2.0f);
font.setColor(Color.RED); font.setColor(Color.RED);
font.draw(batch, "Sorry, demo is not yet implemented", 40, 400); font.draw(batch, "Sorry, demo is not yet implemented", 40, 400);

View File

@ -21,10 +21,11 @@ package com.openeggbert.core.screen;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter; import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.graphics.Color; import com.pixelgamelibrary.api.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.utils.ScreenUtils; import com.badlogic.gdx.utils.ScreenUtils;
import com.openeggbert.core.main.OpenEggbertGame; import com.openeggbert.core.main.OpenEggbertGame;
import com.pixelgamelibrary.api.graphics.BitmapFont;
import java.util.Optional; import java.util.Optional;
/** /**
@ -66,7 +67,7 @@ public class GameScreen extends AbstractGameScreen {
BitmapFont font; BitmapFont font;
font = game.getFont(); font = game.getFont();
font.getData().setScale(2.0f); font.setScale(2.0f);
font.setColor(Color.RED); font.setColor(Color.RED);
font.draw(batch, "Sorry, demo is not yet implemented", 40, 400); font.draw(batch, "Sorry, demo is not yet implemented", 40, 400);

View File

@ -24,14 +24,15 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputAdapter; import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.Preferences; import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.graphics.Color; import com.pixelgamelibrary.api.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.openeggbert.core.gamespace.GameSpace; import com.openeggbert.core.gamespace.GameSpace;
import com.openeggbert.core.main.OpenEggbertGame; import com.openeggbert.core.main.OpenEggbertGame;
import com.openeggbert.core.mod.Mod; import com.openeggbert.core.mod.Mod;
import com.openeggbert.core.mod.ModType; import com.openeggbert.core.mod.ModType;
import com.pixelgamelibrary.api.Pixel; import com.pixelgamelibrary.api.Pixel;
import com.pixelgamelibrary.api.graphics.BitmapFont;
import com.pixelgamelibrary.api.storage.Storage; import com.pixelgamelibrary.api.storage.Storage;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -73,7 +74,7 @@ public class GameSpaceListScreen extends AbstractBasicScreen {
Preferences prefs = Gdx.app.getPreferences("My Preferences"); Preferences prefs = Gdx.app.getPreferences("My Preferences");
prefs.putString("test", "abc"); prefs.putString("test", "abc");
prefs.flush(); prefs.flush();
final Storage storage = Pixel.files().local(); final Storage storage = Pixel.files().localStorage();
storage.createDirectory("modes"); storage.createDirectory("modes");
storage.createDirectory("gameSpaces"); storage.createDirectory("gameSpaces");
System.out.println(storage.debug()); System.out.println(storage.debug());
@ -205,7 +206,7 @@ public class GameSpaceListScreen extends AbstractBasicScreen {
BitmapFont font; BitmapFont font;
font = game.getFont(); font = game.getFont();
font.getData().setScale(4.0f); font.setScale(4.0f);
font.setColor(Color.BLACK); font.setColor(Color.BLACK);
int x = (int) (game.getWidthInPixels() * 0.1875f); int x = (int) (game.getWidthInPixels() * 0.1875f);
int y = (int) (game.getHeightInPixels() * 0.95f); int y = (int) (game.getHeightInPixels() * 0.95f);
@ -215,7 +216,7 @@ public class GameSpaceListScreen extends AbstractBasicScreen {
float margin = 0.05f * game.getWidthInPixels(); float margin = 0.05f * game.getWidthInPixels();
y = (int) (game.getHeightInPixels() * 0.7f); y = (int) (game.getHeightInPixels() * 0.7f);
font.getData().setScale(2.0f); font.setScale(2.0f);
final float spaceBetweenLargeButtons = game.getHeightInPixels() * 0.06f; final float spaceBetweenLargeButtons = game.getHeightInPixels() * 0.06f;
for (int i = 0; i < modsForPage.size(); i++) { for (int i = 0; i < modsForPage.size(); i++) {
buttons[i] = new Rectangle(margin, y, game.getWidthInPixels() * 0.9f, margin * 1.5f); buttons[i] = new Rectangle(margin, y, game.getWidthInPixels() * 0.9f, margin * 1.5f);
@ -264,7 +265,7 @@ public class GameSpaceListScreen extends AbstractBasicScreen {
font.draw(batch, name, margin * 1.5f, buttons[i].y + 0.8f * buttons[i].height); font.draw(batch, name, margin * 1.5f, buttons[i].y + 0.8f * buttons[i].height);
} }
font.getData() font
.setScale(1.5f); .setScale(1.5f);
font.setColor( font.setColor(
0f, 0f, 1f, 1f); 0f, 0f, 1f, 1f);

View File

@ -21,10 +21,11 @@ package com.openeggbert.core.screen;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter; import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.graphics.Color; import com.pixelgamelibrary.api.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.utils.ScreenUtils; import com.badlogic.gdx.utils.ScreenUtils;
import com.openeggbert.core.main.OpenEggbertGame; import com.openeggbert.core.main.OpenEggbertGame;
import com.pixelgamelibrary.api.graphics.BitmapFont;
import java.util.Optional; import java.util.Optional;
/** /**
@ -66,7 +67,7 @@ public class MainHubScreen extends AbstractGameScreen {
BitmapFont font; BitmapFont font;
font = game.getFont(); font = game.getFont();
font.getData().setScale(2.0f); font.setScale(2.0f);
font.setColor(Color.RED); font.setColor(Color.RED);
font.draw(batch, "Sorry, demo is not yet implemented", 40, 400); font.draw(batch, "Sorry, demo is not yet implemented", 40, 400);

View File

@ -19,16 +19,16 @@
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
package com.openeggbert.core.screen; package com.openeggbert.core.screen;
import com.badlogic.gdx.Application;
import static com.badlogic.gdx.Application.LOG_INFO;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.openeggbert.core.gamespace.GameFileType; import com.openeggbert.core.gamespace.GameFileType;
import com.openeggbert.core.main.OpenEggbertGame; import com.openeggbert.core.main.OpenEggbertGame;
import com.openeggbert.core.utils.OpenEggbertUtils; import com.openeggbert.core.utils.OpenEggbertUtils;
import com.pixelgamelibrary.api.Pixel;
import com.pixelgamelibrary.api.Platform;
import com.pixelgamelibrary.api.app.LogLevel;
import com.pixelgamelibrary.api.graphics.SpriteBatch;
import com.pixelgamelibrary.api.graphics.Texture;
import com.pixelgamelibrary.api.screen.ScreenAdapter; import com.pixelgamelibrary.api.screen.ScreenAdapter;
import com.pixelgamelibrary.api.storage.FileHandle;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -74,13 +74,13 @@ public abstract class OpenEggbertScreen extends ScreenAdapter {
if(getScreenType().isPresent() && getScreenType().get().isBasic()) { if(getScreenType().isPresent() && getScreenType().get().isBasic()) {
if (!game.existsImageTexture("BASIC")) { if (!game.existsImageTexture("BASIC")) {
FileHandle fileHandle; FileHandle fileHandle;
if (Gdx.app.getType() == Application.ApplicationType.Android || Gdx.app.getType() == Application.ApplicationType.WebGL) { if (Pixel.app().isOneOfPlatforms(Platform.ANDROID, Platform.WEB)) {
Gdx.app.log("screen","loading from internal"); Pixel.app().log("screen","loading from internal");
fileHandle = Gdx.files.internal("BASIC/BASIC.PNG"); fileHandle = Pixel.files().assets("BASIC/BASIC.PNG");
} else { } else {
Gdx.app.log("screen","loading from classpath"); Pixel.app().log("screen","loading from classpath");
fileHandle = Gdx.files.classpath("BASIC/BASIC.PNG"); fileHandle = Pixel.files().assets("BASIC/BASIC.PNG");
} }
game.loadImageTexture(fileHandle); game.loadImageTexture(fileHandle);
} }
@ -91,27 +91,27 @@ public abstract class OpenEggbertScreen extends ScreenAdapter {
if (!game.existsImageTexture(possibleFileName)) { if (!game.existsImageTexture(possibleFileName)) {
String name = game.getGameSpace().getImage08Directory() + "/" + possibleFileName; String name = game.getGameSpace().getImage08Directory() + "/" + possibleFileName;
Gdx.app.setLogLevel(LOG_INFO); Pixel.app().setLogLevel(LogLevel.INFO);
Gdx.app.log("screen","name=" + name); Pixel.app().log("screen","name=" + name);
FileHandle fileHandle = null; FileHandle fileHandle = null;
if (game.getGameSpace().isEmbeddedAssets()) { if (game.getGameSpace().isEmbeddedAssets()) {
if (Gdx.app.getType() == Application.ApplicationType.Android || Gdx.app.getType() == Application.ApplicationType.WebGL) { if (Pixel.app().isOneOfPlatforms(Platform.ANDROID, Platform.WEB)) {
Gdx.app.log("screen","loading from internal"); Pixel.app().log("screen","loading from internal");
fileHandle = Gdx.files.internal(name); fileHandle = Pixel.files().assets(name);
} else { } else {
Gdx.app.log("screen","loading from classpath"); Pixel.app().log("screen","loading from classpath");
fileHandle = Gdx.files.classpath(name); fileHandle = Pixel.files().assets(name);
} }
} else { } else {
Gdx.app.log("screen","loading from absolute"); Pixel.app().log("screen","loading from absolute");
fileHandle = Gdx.files.absolute(name); fileHandle = Pixel.files().absolute(name);
} }
Gdx.app.log("screen", "fileHandleUpperCase.exists()=" + fileHandle.exists()); Pixel.app().log("screen", "fileHandleUpperCase.exists()=" + fileHandle.exists());
if (fileHandle.exists()) { if (fileHandle.exists()) {
game.loadImageTexture(fileHandle); game.loadImageTexture(fileHandle);

View File

@ -21,10 +21,11 @@ package com.openeggbert.core.screen;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter; import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.graphics.Color; import com.pixelgamelibrary.api.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.utils.ScreenUtils; import com.badlogic.gdx.utils.ScreenUtils;
import com.openeggbert.core.main.OpenEggbertGame; import com.openeggbert.core.main.OpenEggbertGame;
import com.pixelgamelibrary.api.graphics.BitmapFont;
import java.util.Optional; import java.util.Optional;
/** /**
@ -66,7 +67,7 @@ public class SubHubScreen extends AbstractGameScreen {
BitmapFont font; BitmapFont font;
font = game.getFont(); font = game.getFont();
font.getData().setScale(2.0f); font.setScale(2.0f);
font.setColor(Color.RED); font.setColor(Color.RED);
font.draw(batch, "Sorry, demo is not yet implemented", 40, 400); font.draw(batch, "Sorry, demo is not yet implemented", 40, 400);

View File

@ -19,13 +19,14 @@
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
package com.openeggbert.core.screen; package com.openeggbert.core.screen;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputAdapter; import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.utils.ScreenUtils; import com.badlogic.gdx.utils.ScreenUtils;
import com.openeggbert.core.main.OpenEggbertGame; import com.openeggbert.core.main.OpenEggbertGame;
import com.pixelgamelibrary.api.Pixel;
import com.pixelgamelibrary.api.graphics.BitmapFont;
import java.util.function.Function; import java.util.function.Function;
/** /**
@ -56,7 +57,7 @@ public class TestScreen extends OpenEggbertScreen {
ScreenUtils.clear(0.15f, 0.15f, 0.2f, 1f); ScreenUtils.clear(0.15f, 0.15f, 0.2f, 1f);
game.getBatch().begin(); game.getBatch().begin();
Function<String, String> removeCurrentDir = i -> i == null ? null : i.replace(game.getAbsolutePathOfRootDirectory()+ "/", ""); Function<String, String> removeCurrentDir = i -> i == null ? null : i.replace(game.getAbsolutePathOfRootDirectory()+ "/", "");
if (Gdx.app.getType() == Application.ApplicationType.Desktop && game.getGameSpace() != null) { if (Pixel.app().getPlatform().isDesktop() && game.getGameSpace() != null) {
BitmapFont font; BitmapFont font;
font = game.getFont(); font = game.getFont();
int x = 140; int x = 140;