Slick Forums

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

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Feb 07, 2012 9:14 am 
Offline
User avatar

Joined: Sat Apr 30, 2011 6:18 am
Posts: 21
Hi,

Am i missing something?

Code:
import java.awt.Font;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.UnicodeFont;


public class Game extends BasicGame {

   Font font;
   UnicodeFont uniFont;

   public Game() {
      super("Test");
      
      // TODO Auto-generated constructor stub
   }

   @Override
   public void render(GameContainer arg0, Graphics arg1) throws SlickException {
      uniFont.drawString(100, 100, "Some text", Color.blue);
      
   }

   @Override
   public void init(GameContainer arg0) throws SlickException {
      font = new Font("Helvetica", Font.PLAIN, 24);
      uniFont = new UnicodeFont(font, font.getSize(), font.isBold(), font.isItalic());
      
   }

   @Override
   public void update(GameContainer arg0, int arg1) throws SlickException {
      // TODO Auto-generated method stub
      
   }
   
   public static void main (String args[]) throws SlickException {
      AppGameContainer app = new AppGameContainer(new Game());
      app.setDisplayMode(400, 400, false);
      app.start();
   }
}

_________________
You can never finish a program, only put it down.


Top
 Profile  
 
PostPosted: Tue Feb 07, 2012 9:16 am 
Offline
Regular

Joined: Sun Oct 25, 2009 5:24 pm
Posts: 118
You need a little more in order to use a font:

Code:
try {
   UnicodeFont font = new UnicodeFont(ref, size, false, false);
   font.getEffects().add(new ColorEffect(Color.white));
   font.addAsciiGlyphs();
   font.loadGlyphs();
} catch (SlickException e) {
   e.printStackTrace();
}


More speficially, you need a Color and Glyphs to draw.


Top
 Profile  
 
PostPosted: Tue Feb 07, 2012 11:13 am 
Offline
User avatar

Joined: Sat Apr 30, 2011 6:18 am
Posts: 21
Thanks for the help Biki.

I modified my code however this line would not compile. This was using awt.Color.

uniFont.getEffects().add(new ColorEffect(Color.WHITE());

By slightly modifying the code and including the slick.Color import i was able to compile and get a string to screen.

Code:
@Override
   public void render(GameContainer arg0, Graphics arg1) throws SlickException {
      uniFont.drawString(100, 100, "Some text", Color.blue);
      
   }

   @Override
   public void init(GameContainer arg0) throws SlickException {
      font = new Font("Helvetica", Font.PLAIN, 24);
      uniFont = new UnicodeFont(font, font.getSize(), font.isBold(), font.isItalic());
      uniFont.getEffects().add(new ColorEffect());
      uniFont.addAsciiGlyphs();
      uniFont.loadGlyphs();
   }

_________________
You can never finish a program, only put it down.


Top
 Profile  
 
PostPosted: Tue Feb 07, 2012 11:14 am 
Offline
Regular

Joined: Sun Oct 25, 2009 5:24 pm
Posts: 118
Yes that's true, you need to import the Color class of Slick. Glad it worked :D


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 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