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.


Messages - white_nitro0

Pages: [1]
1
Java / Re: Font won't render if it is loaded in a different class
« on: February 26, 2014, 06:27:40 pm »
Just came to the exact same conclusion myself, thanks for your help :)

2
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!

3
Window / Re: [Resolved] User interface elements overlayed on window
« on: February 26, 2014, 12:44:55 pm »
The GUI will update as the game is played, so surely I need to draw the GUI once per frame?

At the minute I have a "Game" class, which has a draw method that is called in the main game loop.

draw(RenderWindow window){

     currentScene.draw(window);

     window.setView(defaultView);
     uiManager.draw(window);

     window.setView(mainView);

}

The currentScene then handles rendering of all of its objects, and the uiManager handles drawing the GUI. The window is passed down because a draw() call is made on each of the objects in turn by the currentScene and uiManager. Does this seem like a sensible approach (before I delve further and further into messy code :))

4
Window / Re: User interface elements overlayed on window
« on: February 26, 2014, 12:22:33 pm »
Thanks, that worked a treat!

The only line that I missed was:

window.setView(viewCenteredOnPlayer);

at the very end so that my coordinate conversions etc were calculated as they were before.

5
Window / Re: User interface elements overlayed on window
« on: February 26, 2014, 12:17:11 pm »
So something along the lines of (pseudocode):

window.setView(viewCenteredOnPlayer);

//do all of the game processing here

window.draw(allGameElements);

gui.setPosition(//top left etc);

window.setView(defaultView);

window.draw(gui);
 

Thanks for the fast response, I'll have a go at implementing that and let you know how it goes.

6
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