Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - white_nitro0

Pages: [1]
1
Java / [Resolved] Font won't render if it is loaded in a different class
« on: February 26, 2014, 05:25:21 pm »
Hi,

For the sake of keeping my code tidy, I've implemented a FontLibrary class:

public class FontLibrary {

    public static Font arial = new Font();

    public static Font getFont(String font){
        if(font.equals("arial")){
             if(arial == null){
                 try{
                     arial.loadFromFile(Paths.get("resources" + File.separatorChar + "fonts" + File.separatorChar + "arial.ttf"));
                 } catch(IOException e){
                     e.printStackTrace();
                 }
             }
            return arial;

        }
        else return null;
    }

I've validated that non-null values are being returned, but when I try to use the FontLibrary to get fonts in a different class, the font is not rendered:

t = new Text("Hello world!", FontLibrary.getFont("arial"), 32);
t.setPosition(0,0);
t.setColor(Color.GREEN);

window.draw(t);

If I do the font loading in the same method as creating the Text object t, it displays as expected.

Can anyone offer any suggestions or point out my mistake?

Thanks in advance!

2
Window / [Resolved] User interface elements overlayed on window
« on: February 26, 2014, 11:56:53 am »
Hi,

I have recently started using SFML (I am actually using JSFML, but this question is generally applicable to all bindings) to build a top down shooter type game.

I am interested in building a user interface that displays things like a HUD, an inventory etc, but am not really sure how to separate these from interactive, collide-able game objects (e.g. if I draw a rectangle in the bottom right corner, what is to stop characters walking over it as if it were part of the map).

It seems like using views might be the way to go, but would this mean I have to draw my HUD somewhere miles away from the game area, then make a "Hud Viewport" look at it and display it on top of my game area?

Any examples or code snippets to get me thinking/started would be much appreciated!

Pages: [1]
anything