Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (592)
Games in Android Showcase (168)
games submitted by our members
Games in WIP (645)
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 2036 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
« 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
« 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.

 
Za\'Anzabar (17 views)
2015-06-29 05:44:54

TritonDreyja (34 views)
2015-06-24 17:10:40

CopyableCougar4 (29 views)
2015-06-23 00:34:45

BurntPizza (32 views)
2015-06-21 20:36:46

cookiecompiler (76 views)
2015-06-11 15:42:53

cookiecompiler (39 views)
2015-06-11 15:41:14

NegativeZero (66 views)
2015-06-11 09:49:18

Fairy Tailz (89 views)
2015-06-11 01:59:47

chrislo27 (61 views)
2015-06-06 18:12:44

Burnsalan20 (74 views)
2015-06-05 03:00:51
How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14
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!