How to create text buttons and use images as buttons in SFML

Aug 31, 2013 at 8:17pm
I'm trying to make a main menu using SFML, but I don't know how to make text buttons or using images as buttons.So how do I do that, and if someone could provide me with examples in code it would be really appreciated!Thanks!

Sep 1, 2013 at 6:55am
ok.

I tried makeing a menu in SFML, and it is hard. (VERY HARD)

It did work though.

Anyway, the best way is to use a GUI lib for SFML. I recommend TGUI, SFGUI, or GEGUI.

http://www.tgui.eu/ <- This is offline alot. I don't know why. :/
http://sfgui.sfml-dev.de/
http://www.cegui.org.uk/wiki/index.php/Main_Page


If you want the long and hard way, I will give it to you on request.
Last edited on Sep 1, 2013 at 6:56am
Sep 1, 2013 at 9:11am
I would like the long and hard way please.Also thanks for the links i will definitely check them out.(Using SFML 2.1 by the way)Thanks!
Last edited on Sep 1, 2013 at 9:25am
Sep 1, 2013 at 11:57pm
closed account (N36fSL3A)
Just draw your images, check if your mouse is inside a rectangle the image's size if it's clicked.

1
2
3
4
5
6
7
8
9
bool active(Obj obj, int mx, int my)
{
    if(mx > obj.box.x && mx < obj.box.x + obj.box.w && my > obj.box.y && my < obj.box.y + obj.box.h)
    {
        return true;
    }

    return false;
}
Last edited on Sep 1, 2013 at 11:57pm
Sep 2, 2013 at 3:29am
Fairly the same as above, except a little different.

You should probably use a graphics editor and make a button image with text already on there. Then use a texture and sprite for the button. If the mouse button gets clicked, then check whether the mouse cursor is over that sprite. (Hint use Sprite.getTextureRect() that returns an intRect and use the intRect.contains() function with the mouse coords) you can also check whether the mouse is over the button at all without being clicked, and then change the color of the sprite.
Sep 2, 2013 at 6:37am
closed account (N36fSL3A)
Yea, but I'd be more efficient to have one button texture and just load a font and draw it.
Topic archived. No new replies allowed.