Skip to content

Commit 43b29e1

Browse files
committed
Try showing how to use Font with an atlas.
This showed BitmapFont before, but I wanted to give TextraTypist a try. There's an issue with center alignment right now, but left-align works, so I use it here.
1 parent bda42f3 commit 43b29e1

File tree

4 files changed

+44
-20
lines changed

4 files changed

+44
-20
lines changed

SquidSquad/DawnSquad/core/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ dependencies {
4747
api "com.github.tommyettinger:funderby:$funderbyVersion"
4848
api "com.github.tommyettinger:jdkgdxds:$jdkgdxdsVersion"
4949
api "com.github.tommyettinger:juniper:$juniperVersion"
50+
api "com.github.tommyettinger:regexodus:$regExodusVersion"
51+
api "com.github.tommyettinger:textratypist:$textratypistVersion"
52+
5053

5154
if(enableGraalNative == 'true') {
5255
implementation "io.github.berstanio:gdx-svmhelper-annotations:$graalHelperVersion"

SquidSquad/DawnSquad/core/src/main/java/com/github/tommyettinger/DawnSquad.java

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import com.github.tommyettinger.ds.ObjectDeque;
3939
import com.github.tommyettinger.ds.ObjectList;
4040
import com.github.tommyettinger.random.ChopRandom;
41+
import com.github.tommyettinger.textra.Font;
42+
import com.github.tommyettinger.textra.Layout;
4143
import com.github.yellowstonegames.core.DescriptiveColor;
4244
import com.github.yellowstonegames.core.FullPalette;
4345
import com.github.yellowstonegames.grid.*;
@@ -126,7 +128,8 @@ private boolean onGrid(int screenX, int screenY) {
126128
return screenX >= 0 && screenX < placeWidth && screenY >= 0 && screenY < placeHeight;
127129
}
128130

129-
private BitmapFont font;
131+
private Font font;
132+
private Layout gameOver;
130133
private Viewport mainViewport;
131134
private Viewport guiViewport;
132135
private Camera camera;
@@ -324,6 +327,14 @@ public void restart(long seed) {
324327
lang = '"' + Language.DEMONIC.sentence(rng, 4, 7,
325328
new String[]{",", ",", ",", " -"}, new String[]{"...\"", ", heh...\"", ", nyehehe...\"", "!\"", "!\"", "!\"", "!\" *PTOOEY!*",}, 0.2);
326329

330+
gameOver.clear();
331+
332+
gameOver.setTargetWidth(shownWidth * cellWidth);
333+
font.markup("[RED]YOUR CRAWL IS OVER!\n" +
334+
"[GRAY]A monster sniffs your corpse and says,\n[FOREST]"+
335+
lang + "\n[GRAY]q to quit.\n[YELLOW]r to restart.", gameOver);
336+
font.regenerateLayout(gameOver);
337+
327338
}
328339

329340
@Override
@@ -349,12 +360,18 @@ public void create() {
349360

350361
// Stores all images we use here efficiently, as well as the font image
351362
atlas = new TextureAtlas(Gdx.files.internal("dawnlike/Dawnlike.atlas"), Gdx.files.internal("dawnlike"));
352-
font = new BitmapFont(Gdx.files.internal("dawnlike/font.fnt"), atlas.findRegion("font"));
353-
// font = new BitmapFont(Gdx.files.internal("dawnlike/PlainAndSimplePlus.fnt"), atlas.findRegion("PlainAndSimplePlus"));
354-
font.getData().markupEnabled = true;
355-
font.setUseIntegerPositions(false);
356-
font.getData().setScale(3);
363+
// font = new BitmapFont(Gdx.files.internal("dawnlike/font.fnt"), atlas.findRegion("font"));
364+
// font.getData().markupEnabled = true;
365+
// font.setUseIntegerPositions(false);
366+
// font.getData().setScale(3);
367+
357368
// font = generateFreetypeFont(48);
369+
370+
font = new Font(Gdx.files.internal("dawnlike/font.fnt"), atlas.findRegion("font"), Font.DistanceFieldType.STANDARD, 0, 0, 0, 0, false);
371+
font.scale(3, 3);
372+
373+
gameOver = new Layout(font);
374+
358375
vision.rememberedColor = OKLAB_MEMORY;
359376

360377
// Pixmap pCursor = new Pixmap(cellWidth, cellHeight, Pixmap.Format.RGBA8888);
@@ -756,13 +773,14 @@ public void render() {
756773
batch.setProjectionMatrix(guiViewport.getCamera().combined);
757774
batch.begin();
758775
float wide = guiViewport.getWorldWidth(),
759-
x = playerSprite.getX() - guiViewport.getWorldWidth() * 0.5f,
776+
x = playerSprite.getX() - wide * 0.4f,
760777
y = playerSprite.getY();
761-
font.draw(batch, "[RED]YOUR CRAWL IS OVER!", x, y + 2 * font.getLineHeight(), wide, Align.center, true);
762-
font.draw(batch, "[GRAY]A monster sniffs your corpse and says,", x, y + font.getLineHeight(), wide, Align.center, true);
763-
font.draw(batch, "[FOREST]" + lang, x, y, wide, Align.center, true);
764-
font.draw(batch, "[GRAY]q to quit.", x, y - 2 * font.getLineHeight(), wide, Align.center, true);
765-
font.draw(batch, "[YELLOW]r to restart.", x, y - 4 * font.getLineHeight(), wide, Align.center, true);
778+
font.drawGlyphs(batch, gameOver, x, y + 2 * font.cellHeight, Align.left);
779+
// font.draw(batch, "[RED]YOUR CRAWL IS OVER!", x, y + 2 * font.getLineHeight(), wide, Align.center, true);
780+
// font.draw(batch, "[GRAY]A monster sniffs your corpse and says,", x, y + font.getLineHeight(), wide, Align.center, true);
781+
// font.draw(batch, "[FOREST]" + lang, x, y, wide, Align.center, true);
782+
// font.draw(batch, "[GRAY]q to quit.", x, y - 2 * font.getLineHeight(), wide, Align.center, true);
783+
// font.draw(batch, "[YELLOW]r to restart.", x, y - 4 * font.getLineHeight(), wide, Align.center, true);
766784
batch.end();
767785
if (input.isKeyPressed(Q))
768786
Gdx.app.exit();
@@ -819,9 +837,9 @@ public void render() {
819837
guiViewport.apply(false);
820838
batch.setProjectionMatrix(guiViewport.getCamera().combined);
821839
batch.begin();
822-
pos.set(10, Gdx.graphics.getHeight() - font.getLineHeight());
840+
pos.set(10, Gdx.graphics.getHeight() - font.cellHeight);
823841
guiViewport.unproject(pos);
824-
font.draw(batch, "[GRAY]Current Health: [RED]" + health + "[WHITE] at "
842+
font.drawMarkupText(batch, "[GRAY]Current Health: [RED]" + health + "[WHITE] at "
825843
+ Gdx.graphics.getFramesPerSecond() + " FPS", pos.x, pos.y);
826844

827845
// pos.set(input.getDeltaX(), -input.getDeltaY());

SquidSquad/DawnSquad/gradle.properties

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ graalvmVersion=22.3.1
99
gdxVersion=1.13.1
1010
gwtFrameworkVersion=2.11.0
1111
gwtPluginVersion=1.1.29
12-
digitalVersion=0.6.2
13-
juniperVersion=0.6.7
14-
regexodusVersion=0.1.19
12+
digitalVersion=0.7.0
13+
juniperVersion=0.6.9
14+
regExodusVersion=0.1.19
1515
funderbyVersion=0.1.2
16-
jdkgdxdsVersion=1.10.1
17-
squidSquadVersion=81df56d994
16+
jdkgdxdsVersion=1.11.0
17+
squidSquadVersion=d6297d3008
18+
#squidSquadVersion=81df56d994
1819
#squidSquadVersion=9f41d7b883
1920
#squidSquadVersion=d3224c1abe
2021
#squidSquadVersion=4.0.0-beta1
2122
#freetypeGwtVersion=1.9.10.1
23+
textratypistVersion=eceab53c8d
2224
projectVersion=0.0.1

SquidSquad/DawnSquad/html/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ dependencies {
4141
implementation "com.github.tommyettinger:jdkgdxds:$jdkgdxdsVersion:sources"
4242
implementation "com.github.tommyettinger:crux:0.1.2:sources"
4343
implementation "com.github.tommyettinger:funderby:$funderbyVersion:sources"
44-
implementation "com.github.tommyettinger:regexodus:$regexodusVersion:sources"
44+
implementation "com.github.tommyettinger:regexodus:$regExodusVersion:sources"
45+
implementation "com.github.tommyettinger:textratypist:$textratypistVersion:sources"
4546

4647
// implementation "com.squidpony:squidcore:$squidSquadVersion:sources"
4748
// implementation "com.squidpony:squidgrid:$squidSquadVersion:sources"

0 commit comments

Comments
 (0)