Issue loading custom font

后端 未结 3 1949
天涯浪人
天涯浪人 2021-01-23 02:16

I am attempting to load a font, in slick2d, which (in eclipse) is located at: \"resources\\fonts\\slkscr.ttf\" with the following code:

private void         


        
相关标签:
3条回答
  • 2021-01-23 02:41

    You're loading the font all wrong, you should look at the examples here Slick Wiki - True Type Fonts

    0 讨论(0)
  • 2021-01-23 02:43
    private void loadResources() throws FontFormatException, IOException  {
            Font fontRaw = Font.createFont(Font.TRUETYPE_FONT, new File("resources/fonts/slkscr.ttf"));
            Font fontBase = fontRaw.deriveFont(28f);
            this.font = new TrueTypeFont(fontBase, false);
    }
    
    0 讨论(0)
  • 2021-01-23 02:43

    Put a leading slash to indicate to search from the root of the class-path, vis.

    ..getResourceAsStream("/resources/fonts/slkscr.ttf")..
    

    As an aside. That stream closed message might be telling us that createFont requires a repositionable InputStream. Try instead:

    getResource("/resources/fonts/slkscr.ttf")
    

    ..or..

    getResource("/slkscr.ttf")
    

    ..depending upon path.

    0 讨论(0)
提交回复
热议问题