Wrapping up a Java2D game: custom fonts and transparent pngs

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 display, 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:

[code]
ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, System.class.getResourceAsStream("/fonts/digital-7.ttf")));[/code]

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:

[code]
g.setFont(new Font("digital-7", Font.BOLD, 20));
[/code]

Updated results for the game are here and the 2d game engine here.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.