Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (523)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Custom Fonts  (Read 2302 times)
0 Members and 1 Guest are viewing this topic.
Offline cubemaster21
« Posted 2012-04-14 18:07:05 »

I've been working on my own game for a while and think that it's about time that i included my own custom font, like in minecraft, or CatacombSnatch. Does anyone know how to help me out with this?

Check out my game, Viking Supermarket Smash
http://www.java-gaming.org/topics/iconified/28984/view.html
Offline davedes
« Reply #1 - Posted 2012-04-14 18:24:20 »

Look into MatthiasM's Font Tool (which is part of TWL's theme editor). It can export a TTF font as a bitmap image with an XML or text file. Then, you simply read the font file and its kerning information and use it when rendering each glyph. For that, look into TWL's BitmapFont class:
http://hg.picibo.com/twl/file/1055c387f54e/src/de/matthiasmann/twl/renderer/lwjgl/BitmapFont.java

Alternatively, you could simply use TWL or another GUI library, as most of them support text rendering (with line wrapping, styling, etc).

Offline ra4king

JGO Kernel


Medals: 355
Projects: 3
Exp: 5 years


I'm the King!


« Reply #2 - Posted 2012-04-14 18:29:51 »

I believe the way Notch does it is he manually draws the characters onto an image and then has a method for drawing the specified characters from that image.

Look into the g.drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) method.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cubemaster21
« Reply #3 - Posted 2012-04-14 20:36:02 »

Thanks, I've looked into that and now the font will render... just not correctly...

Here is the code I'm using:
http://pastebin.java-gaming.org/54a6b9d54

Check out my game, Viking Supermarket Smash
http://www.java-gaming.org/topics/iconified/28984/view.html
Offline _Al3x

Senior Devvie


Medals: 7


Indie Games FTW!


« Reply #4 - Posted 2012-04-14 20:38:48 »

1  
2  
3  
4  
public static void Render(Graphics2D g, String msg, int x, int y){
       msg = msg.toUpperCase();
       int length = msg.length();
       ;


There's a ; that shouldn't be there, but I don't think that's the problem, will you tell us what's not correct? Smiley

Offline ra4king

JGO Kernel


Medals: 355
Projects: 3
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2012-04-14 20:49:18 »

Shocked you re-read and re-draw the image every single time you call render! Don't do that! Load the image once and store it as a variable to be reused.

When drawing the letter, your destination x2 should be x+8 not x + (length * 8 ) since that's making the letter as wide as the entire word length Wink

Also, since your letters at 8x8 pixels, you should be doing (c%29) * 8 and (c/29) * 8

Lastly, you should check if c == -1 so it can skip drawing that non-existant letter. This will probably be needed for spaces so don't forget to add 8 to x, or better yet, don't add 8 to x and simply add i * 8 to x when drawing Smiley

Offline cubemaster21
« Reply #6 - Posted 2012-04-14 21:07:12 »

Shocked you re-read and re-draw the image every single time you call render! Don't do that! Load the image once and store it as a variable to be reused.

When drawing the letter, your destination x2 should be x+8 not x + (length * 8 ) since that's making the letter as wide as the entire word length Wink

Also, since your letters at 8x8 pixels, you should be doing (c%29) * 8 and (c/29) * 8

Lastly, you should check if c == -1 so it can skip drawing that non-existant letter. This will probably be needed for spaces so don't forget to add 8 to x, or better yet, don't add 8 to x and simply add i * 8 to x when drawing Smiley
THIS. Thank you so much, I think that you can tell that I'm relatively new at this. This solved my problems. You, my sir, are awesome.

Check out my game, Viking Supermarket Smash
http://www.java-gaming.org/topics/iconified/28984/view.html
Offline ra4king

JGO Kernel


Medals: 355
Projects: 3
Exp: 5 years


I'm the King!


« Reply #7 - Posted 2012-04-14 21:16:34 »

Shocked you re-read and re-draw the image every single time you call render! Don't do that! Load the image once and store it as a variable to be reused.

When drawing the letter, your destination x2 should be x+8 not x + (length * 8 ) since that's making the letter as wide as the entire word length Wink

Also, since your letters at 8x8 pixels, you should be doing (c%29) * 8 and (c/29) * 8

Lastly, you should check if c == -1 so it can skip drawing that non-existant letter. This will probably be needed for spaces so don't forget to add 8 to x, or better yet, don't add 8 to x and simply add i * 8 to x when drawing Smiley
THIS. Thank you so much, I think that you can tell that I'm relatively new at this. This solved my problems. You, my sir, are awesome.
Glad to help! Grin

EDIT: One thing I didn't mention, no need to round that last source y2, since you're already doing int division.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Gibbo3771 (12 views)
2014-11-24 19:59:16

trollwarrior1 (35 views)
2014-11-22 12:13:56

xFryIx (74 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (40 views)
2014-11-12 21:09:33

kovacsa (66 views)
2014-11-07 19:57:14

TehJavaDev (70 views)
2014-11-03 22:04:50

BurntPizza (68 views)
2014-11-03 18:54:52

moogie (83 views)
2014-11-03 06:22:04
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!