Slick Forums

Discuss the Slick 2D Library
It is currently Sat May 18, 2013 9:27 am

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Font Colours?
PostPosted: Tue Jul 10, 2012 7:01 pm 
Offline
User avatar

Joined: Wed Jun 20, 2012 10:33 pm
Posts: 35
Location: Doncaster, South Yorkshire
Is it possible to change the font and/or colour of text in Slick?


Top
 Profile  
 
 Post subject: Re: Font Colours?
PostPosted: Tue Jul 10, 2012 7:08 pm 
Offline
User avatar

Joined: Wed Jun 20, 2012 8:10 pm
Posts: 54
Yes.

You can do a font.getEffects().add(new ColorEffect(java.awt.Color.RED));
(Maybe you have to remove the old effects in case there is already a color set.

_________________
Seventeen


Top
 Profile  
 
 Post subject: Re: Font Colours?
PostPosted: Tue Jul 10, 2012 7:21 pm 
Offline
User avatar

Joined: Wed Jun 20, 2012 10:33 pm
Posts: 35
Location: Doncaster, South Yorkshire
Thanks man.

What do I need to import to get that code to work?


Top
 Profile  
 
 Post subject: Re: Font Colours?
PostPosted: Tue Jul 10, 2012 7:45 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1466
Use an IDE with auto import, like Eclipse -- just hit Control + Shift + O. Alternatively check the JavaDocs if you have some unusual desire to type it out manually:
http://slick.cokeandcode.com/javadoc/or ... ffect.html


Top
 Profile  
 
 Post subject: Re: Font Colours?
PostPosted: Tue Jul 10, 2012 7:46 pm 
Offline
User avatar

Joined: Wed Jun 20, 2012 10:33 pm
Posts: 35
Location: Doncaster, South Yorkshire
Yeah, I'm using Eclipse, but I'm getting an error on that :(


Top
 Profile  
 
 Post subject: Re: Font Colours?
PostPosted: Tue Jul 10, 2012 8:04 pm 
Offline

Joined: Mon May 07, 2012 11:36 pm
Posts: 93
I'm pretty sure its just
Code:
g.setColor(Color.red);

Make sure you import Slicks color and not AWT's color.


Top
 Profile  
 
 Post subject: Re: Font Colours?
PostPosted: Tue Jul 10, 2012 8:16 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1466
Oops, didn't read your question. :)
Quote:
Is it possible to change the font and/or colour of text in Slick?


You don't need to worry about ColorEffect. That's for UnicodeFont, which you shouldn't be using anyways (AngelCodeFont is almost always a better choice).

To create a font, you need to load it up in a font creator like TWL's font tool or Slick's Hiero. I'd suggest TWL as it's a little more robust, but either will work. If you use TWL, export with "Text" instead of XML.

Load a font:
Code:
font = new AngelCodeFont("font.fnt", "font.png");


To change colors and render text:
Code:
font.drawString(x, y, "blah", Color.red);


Top
 Profile  
 
 Post subject: Re: Font Colours?
PostPosted: Tue Jul 10, 2012 8:47 pm 
Offline
User avatar

Joined: Wed Jun 20, 2012 10:33 pm
Posts: 35
Location: Doncaster, South Yorkshire
AtomizerZero wrote:
I'm pretty sure its just
Code:
g.setColor(Color.red);

Make sure you import Slicks color and not AWT's color.


This is spot on, thanks!


Top
 Profile  
 
 Post subject: Re: Font Colours?
PostPosted: Tue Jul 10, 2012 10:23 pm 
Offline

Joined: Mon May 07, 2012 11:36 pm
Posts: 93
Delinitor wrote:
AtomizerZero wrote:
I'm pretty sure its just
Code:
g.setColor(Color.red);

Make sure you import Slicks color and not AWT's color.


This is spot on, thanks!


No problem! Just remember, everything being drawn with "g" after that will be red or whatever color you set it to, so be sure to set it to the colour you need again. I think davedes' approach is better overall, because there'll be no need to set the colour for other objects.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group