chore(assets): move black & white texture to Assets
This commit is contained in:
@ -16,12 +16,4 @@ public class Constants {
|
|||||||
public static final int WINDOW_WIDTH = 1280;
|
public static final int WINDOW_WIDTH = 1280;
|
||||||
public static final int WINDOW_HEIGHT = 720;
|
public static final int WINDOW_HEIGHT = 720;
|
||||||
public static final String WINDOW_TITLE = "Moongazer";
|
public static final String WINDOW_TITLE = "Moongazer";
|
||||||
public static final Texture TEXTURE_WHITE = new Texture(new Pixmap(1, 1, Pixmap.Format.RGBA8888) {{
|
|
||||||
setColor(Color.WHITE);
|
|
||||||
fill();
|
|
||||||
}});
|
|
||||||
public static final Texture TEXTURE_BLACK = new Texture(new Pixmap(1, 1, Pixmap.Format.RGBA8888) {{
|
|
||||||
setColor(Color.BLACK);
|
|
||||||
fill();
|
|
||||||
}});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,8 @@ import org.slf4j.Logger;
|
|||||||
import com.badlogic.gdx.assets.AssetManager;
|
import com.badlogic.gdx.assets.AssetManager;
|
||||||
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
|
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
|
||||||
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
|
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.graphics.Pixmap;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGeneratorLoader;
|
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGeneratorLoader;
|
||||||
@ -19,9 +21,21 @@ public class Assets {
|
|||||||
private static final ArrayList<String> loadedFonts = new ArrayList<>();
|
private static final ArrayList<String> loadedFonts = new ArrayList<>();
|
||||||
private static boolean startLoadAll = false;
|
private static boolean startLoadAll = false;
|
||||||
private static boolean loadedAll = false;
|
private static boolean loadedAll = false;
|
||||||
|
private static Texture textureWhite;
|
||||||
|
private static Texture textureBlack;
|
||||||
|
|
||||||
public static <T> T getAsset(String fileName, Class<T> type) {
|
public static <T> T getAsset(String fileName, Class<T> type) {
|
||||||
|
try {
|
||||||
|
if (!assetManager.isLoaded(fileName, type)) {
|
||||||
|
log.warn("Asset not loaded: {}", fileName);
|
||||||
|
assetManager.load(fileName, type);
|
||||||
|
assetManager.finishLoadingAsset(fileName);
|
||||||
|
}
|
||||||
return assetManager.get(fileName, type);
|
return assetManager.get(fileName, type);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to load asset: {}", fileName, e);
|
||||||
|
throw new RuntimeException("Asset loading failed: " + fileName, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,6 +71,8 @@ public class Assets {
|
|||||||
*/
|
*/
|
||||||
public static void loadIntroAndWait() {
|
public static void loadIntroAndWait() {
|
||||||
assetManager.load("icons/logo.png", Texture.class);
|
assetManager.load("icons/logo.png", Texture.class);
|
||||||
|
getBlackTexture();
|
||||||
|
getWhiteTexture();
|
||||||
waitUntilLoaded();
|
waitUntilLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +108,37 @@ public class Assets {
|
|||||||
return assetManager;
|
return assetManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Texture getWhiteTexture() {
|
||||||
|
if (textureWhite == null) {
|
||||||
|
Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
|
||||||
|
pixmap.setColor(Color.WHITE);
|
||||||
|
pixmap.fill();
|
||||||
|
textureWhite = new Texture(pixmap);
|
||||||
|
pixmap.dispose(); // Important: dispose pixmap after creating texture
|
||||||
|
}
|
||||||
|
return textureWhite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Texture getBlackTexture() {
|
||||||
|
if (textureBlack == null) {
|
||||||
|
Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
|
||||||
|
pixmap.setColor(Color.BLACK);
|
||||||
|
pixmap.fill();
|
||||||
|
textureBlack = new Texture(pixmap);
|
||||||
|
pixmap.dispose();
|
||||||
|
}
|
||||||
|
return textureBlack;
|
||||||
|
}
|
||||||
|
|
||||||
public static void dispose() {
|
public static void dispose() {
|
||||||
assetManager.dispose();
|
assetManager.dispose();
|
||||||
|
if (textureWhite != null) {
|
||||||
|
textureWhite.dispose();
|
||||||
|
textureWhite = null;
|
||||||
|
}
|
||||||
|
if (textureBlack != null) {
|
||||||
|
textureBlack.dispose();
|
||||||
|
textureBlack = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,7 +45,7 @@ public class Intro extends Scene {
|
|||||||
log.info("All assets loaded successfully.");
|
log.info("All assets loaded successfully.");
|
||||||
game.transition = new Transition(game, this, game.mainMenuScene, State.MAIN_MENU, 1000);
|
game.transition = new Transition(game, this, game.mainMenuScene, State.MAIN_MENU, 1000);
|
||||||
}
|
}
|
||||||
batch.draw(TEXTURE_BLACK, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
batch.draw(Assets.getBlackTexture(), 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ScreenUtils.clear(Color.BLACK);
|
ScreenUtils.clear(Color.BLACK);
|
||||||
|
|||||||
@ -30,7 +30,7 @@ public class MainMenu extends Scene {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void render(SpriteBatch batch) {
|
public void render(SpriteBatch batch) {
|
||||||
batch.draw(TEXTURE_WHITE, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
batch.draw(Assets.getWhiteTexture(), 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||||
// Unneeded as using Scene2D Stage to render the label
|
// Unneeded as using Scene2D Stage to render the label
|
||||||
// textLabel.draw(batch, 1.0f);
|
// textLabel.draw(batch, 1.0f);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user