Wrapping Up a Java2D Game: Custom Fonts and Transparent PNGs
The retro-modern aesthetic is really popular in gaming, especially with indie titles. Here's how to create custom fonts and transparent PNGs to capture that old-school vibe.
Join the DZone community and get the full member experience.Join For Free
a while back (turns out it was about 8 years ago) i started working on a simple 2d game in the style of nintendo game and watch lcd games that were popular in the 1980s, but i never finished it completely.
i dug up the source and committed it to github in its original state, how i last left it, and then took a look at wrapping up the last few issues and adding finishing touches.
here’s the source for the game, and here’s the source for a generic 2d game framework that i abstracted from the game as i was developing it. here’s a couple of posts from when i was actively working on developing this, here and here .
there was a couple of bugs in the animation that i never fixed, and i wanted to polish it up a bit.
it never really had the look of an old monochrome lcd displ
ay, so i first changed the background (using a color dropper to pick a color from online photos), but then realized none of the images were transparent so it ended up looking like this:
notice the bank on the top-left now has the first of the sprites updated to add transparency. i did this by adding an alpha layer in gimp per simple steps here . i updated each of the image sprites to resave them as pngs with a transparent layer.
the end result now looks like this:
the lcd segment font is from http://www.styleseven.com/ . to load the custom font, use:
ge = graphicsenvironment.getlocalgraphicsenvironment(); ge.registerfont(font.createfont(font.truetype_font, system.class.getresourceasstream("/fonts/digital-7.ttf")));
and then when you need to use it, create a new font using it’s name and you can use it in place of any regular system font:
g.setfont(new font("digital-7", font.bold, 20));
Published at DZone with permission of Kevin Hooke, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.