Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
games submitted by our members
Games in WIP (563)
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  
  Fonts.  Using sprites?  (Read 1943 times)
0 Members and 1 Guest are viewing this topic.
Offline xeturnerx

Junior Newbie




Java games rock!


« Posted 2004-06-13 04:01:33 »

I read the Space Invaders 101 tutorial on Java 2-D, and at the end when he was mentioning possible future tutes, he says something about "Sprite based fonts".  I don't really know what this is, but I'm pretty sure I need it.  The other day, I was trying to make some kind of in-game window system for displaying messages, but the spacing is so off when you try to use drawString(), so I couldn't get the windows to fit the text perfectly.  Are sprite based fonts the solution to this problem?
Offline kevglass

JGO Kernel


Medals: 165
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2004-06-13 06:08:37 »

Sprite based fonts are when you use a sprite for each character your going to display. When you want to write something on the screen you use a series of sprites. So to write "TEST" you'd use four sprites, one for each letter.

This gives you better performance (normally), nicer looking fonts but uses up lots of graphics memory.

Kev

Offline xeturnerx

Junior Newbie




Java games rock!


« Reply #2 - Posted 2004-06-13 15:59:16 »

Yeah... I guess if I did that I would have to write some way to map characters from my strings to the appropriate sprite.  That seems like some extra work in the beginnning, but it seems like it'd save me some time in the long run.  Thanks for the reply.   Grin
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ribot

Junior Member




Ribot - mobile UI specialist


« Reply #3 - Posted 2004-06-13 17:02:39 »

What's the best way of doing this?  If I recall, if you call evt.getKeyCode() this will return the same int value for 'a' as for 'A'.  I know you can also detect if the shift key is depressed with something like evt.isShiftPressed().  What is the most efficient method for constructing this mapping?

Regards,

Ribot.

http://ribot.co.uk - design agency focused on mobile
http://www.retrospecs.co.uk - online vintage eyewear store
Offline sponge

Senior Newbie




Ek is Java.


« Reply #4 - Posted 2004-06-15 17:09:51 »

I can't see why you'd want to use sprite fonts, unless it is to design your own font.  Why don't your messages display correctly? Remember, the x and y values you use with drawString aren't used for the top left point of the drawn string (check out the API). If i remember correctly, the x and y is used to position the baseline.
Offline kevglass

JGO Kernel


Medals: 165
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #5 - Posted 2004-06-15 17:19:49 »

The message displays normally with drawString(), moving to sprite based fonts is a performance thing. Blitting sprites to the screen is considerably faster than tracing round a font glyph for each letter.

If you move to OpenGL this becomes more important because while you can use dynamic textures converted from buffered images into which you've used drawString() its far more efficent to push all your sprite fonts off onto texture memory at initialisation onto the graphics card and just use changes to your texture coordinates to actually write the text to the screen.

There are of course positives and negatives to both methods.

As to a good algorithm I've found an array of character code indexed images works quite nicely in Java 2D. If you're looking for a solution for OpenGL it might be worth checking out NeHe Lesson 17 (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=17)

Kev

Offline ribot

Junior Member




Ribot - mobile UI specialist


« Reply #6 - Posted 2004-06-15 19:17:55 »

Many thanks for the reminder kev, I had totally forgotten about nehe's bitmap texture tutorial.

http://ribot.co.uk - design agency focused on mobile
http://www.retrospecs.co.uk - online vintage eyewear store
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #7 - Posted 2004-06-16 09:34:21 »

http://members.rogers.com/mark.bernard/NeHeGLLessons.zip has a Java version of that tutorial.  It also has the tutorial where the texture font is dynamically created at initialization.(#13 I think)

Offline ribot

Junior Member




Ribot - mobile UI specialist


« Reply #8 - Posted 2004-06-16 10:41:29 »

Thanks, I've got my basic font sprites working now!  Cheesy

The outcome is a little bit ugly (unless you use a fixed width font), so I'm off to program in variable width fonts.

http://ribot.co.uk - design agency focused on mobile
http://www.retrospecs.co.uk - online vintage eyewear store
Offline nech_neb

Junior Member




Java for LIFE !!!


« Reply #9 - Posted 2004-07-20 05:46:06 »

I tried using the lwjgl tutorial 13 for getting fonts,
and it seems like I can't draw any other objects after
after initializing the fonts....

I'm not exactly sure what the dynamically font creation
code is doing. I was wondering if someone can point out, what else needs to be done after the buildFont()
function has been called. In order for polygons to be
drawn.

Thanks in advance.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nech_neb

Junior Member




Java for LIFE !!!


« Reply #10 - Posted 2004-07-20 14:33:59 »

Ok...
I give up,
and decided to use sprites....
Nehe lesson 17 way...
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.

Grunnt (18 views)
2014-09-23 14:38:19

radar3301 (14 views)
2014-09-21 23:33:17

BurntPizza (31 views)
2014-09-21 02:42:18

BurntPizza (22 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (29 views)
2014-09-20 20:14:06

BurntPizza (33 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (75 views)
2014-09-10 13:57:51

TehJavaDev (105 views)
2014-09-10 06:39:09
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!