Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
games submitted by our members
Games in WIP (562)
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  
  How to set font size in Slick 2D  (Read 781 times)
0 Members and 1 Guest are viewing this topic.
Offline streek405

Senior Newbie





« Posted 2014-01-20 20:24:42 »

I tried doing this to change the font size of my intro, but I am getting an error of "the method setFont() in the type Graphics is not applicable for the arguments (Font) "

Here is what I've tried:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
import java.awt.Font;

import org.lwjgl.input.Mouse;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class FirstGameMenu extends BasicGameState{
   
   Font font;
   
   public FirstGameMenu(int state){
     
   }
   
   // load all fonts, graphics, sounds, etc
  public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
      font = new Font("Time New Roman", Font.BOLD, 20);
   }

   //draw stuff on the screen
  public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
     
      Image enter = new Image("res1/button2.png");
      //set the coordinates for the pic
     g.drawImage(enter, 315, 180);
      g.setFont(font);
      g.drawString("How to Play", 385, 460);
      g.drawString("Exit", 415, 520);  
   }
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #1 - Posted 2014-01-20 20:34:13 »

Check this out:
http://lwjgl.org/wiki/index.php?title=Slick-Util_Library_-_Part_3_-_TrueType_Fonts_for_LWJGL
Should tell you everything you need to know!

Offline streek405

Senior Newbie





« Reply #2 - Posted 2014-01-21 21:26:02 »

For this line:
1  
InputStream inputStream = ResourceLoader.getResourceAsStream("myfont.ttf");

is the myfont.tff an actual file or something? Does that mean I have to save the word (the one that I want to increase the font size) to a file or can I just simply type in the word that I want to resize?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #3 - Posted 2014-01-21 21:34:15 »

It's a true type font file. Nearly all fonts are created in .ttf format. You can download fonts online, or if using windows fonts, the ttf files are at control panel >> appearance and personalization >> fonts.

Why are all OpenGL tutorials written in Brainf**k?
Offline streek405

Senior Newbie





« Reply #4 - Posted 2014-01-21 22:13:35 »

Ok thanks!
Do you know how I can fix this error that I am getting for that line though? I am getting:
1  
2  
3  
4  
5  
6  
7  
8  
9  
java.lang.RuntimeException: Resource not found: Pokemon Hollow.ttf
   at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:69)
   at randoms.FontExample.init(FontExample.java:89)
   at randoms.FontExample.start(FontExample.java:27)
   at randoms.FontExample.main(FontExample.java:115)
Exception in thread "main" java.lang.NullPointerException
   at randoms.FontExample.render(FontExample.java:107)
   at randoms.FontExample.start(FontExample.java:31)
   at randoms.FontExample.main(FontExample.java:115)

Which first points at this line of code:
1  
         InputStream inputStream   = ResourceLoader.getResourceAsStream("Pokemon Hollow.ttf");//the font style


Is it because I am not calling the correct location of this font or something?
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #5 - Posted 2014-01-21 22:18:47 »

Yes, you'll need to add a leading slash before the name of the file, and you will also have to add the path, minus the "/root". So for instance, if your TTF file was in "res/fonts/font.ttf", the path would be "/fonts/font.ttf".

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.

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

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

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

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

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

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

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

TehJavaDev (97 views)
2014-09-10 06:39:09

Tekkerue (49 views)
2014-09-09 02:24:56

mitcheeb (70 views)
2014-09-08 06:06:29
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!