Does anybody know if it is possible to use a font that isn't a standard one (Calibri, Arial, etc.) I am making a Flappy Bird game and want to change the font of the counter to the original flappy bird font.
Thanks on forward.


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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | import java.awt.Color; import java.awt.FontFormatException; import java.io.IOException; import java.io.PrintStream; import greenfoot.GreenfootImage; /** * Custom Font. * * @author Lollygag * @version 2014 */ public class Font { /** * An example of a method - replace this comment with your own * * @param y a sample parameter for a method * @return the sum of x and y */ public static GreenfootImage drawString(String str, Color color, String font, float size) { // put your code here int strLength = (str.length() + 2 ) * ( int )size; GreenfootImage img = new GreenfootImage(strLength, ( int )size); img.setColor(color); img.setFont(getFont(font, size)); img.drawString(str, 0 , ( int )size); return img; } /** * An example of a method - replace this comment with your own * * @param y a sample parameter for a method * @return the sum of x and y */ public static GreenfootImage drawString2(String str, Color color, String font, float size) { // put your code here int strLength = (str.length() + 2 ) * ( int )size; GreenfootImage img = new GreenfootImage(strLength, ( int )size); img.setColor(Common.TEAL); img.fill(); img.setColor(color); img.setFont(getFont(font, size)); img.drawString(str, 0 , ( int )size); return img; } /** * An example of a method - replace this comment with your own * * @param y a sample parameter for a method * @return the sum of x and y */ private static java.awt.Font getFont(String name, float size) { // put your code here java.awt.Font font = null ; try { java.awt.Font tmpFont = java.awt.Font.createFont( 0 , Font. class .getResourceAsStream( "/fonts/" + name + ".TTF" )); font = tmpFont.deriveFont(size); } catch (IOException e) { System.err.println(e.getMessage()); } catch (FontFormatException e) { System.err.println(e.getMessage()); } return font; } } |