Hello fellas!
I'm new to SFML so my problem is maybe stupid. I made a main menu and my problem is that if I start the program I get this loading mouse icon and the programm isn't responding to my input. The input is checked in another than the menu class so maybe thats my problem but I'm not sure.
Here's my code:
menu header:
#pragma once
#include <SFML/Graphics.hpp>
class button {
private:
sf::Texture bttex;
sf::Sprite btspr;
sf::Texture btctex;
sf::Font font;
sf::Text txt;
sf::Mouse m;
//font mit fkt set fonttext und wenn maus intersected && linksclick ausführen
public:
button() {
bttex.loadFromFile("C:/Users/Andreas/source/repos/jumpnrunSFML/Debug/Media/button.jpg");
btspr.setTexture(bttex);
btctex.loadFromFile("C:/Users/Andreas/source/repos/jumpnrunSFML/Debug/Media/buttonclicked.jpg");
font.loadFromFile("C:/Users/Andreas/source/repos/jumpnrunSFML/Debug/Media/arialbd.ttf");
txt.setFont(font);
txt.setCharacterSize(60);
txt.setFillColor(sf::Color::Black);
}
void settxt(std::string s) {
txt.setString(s);
}
void setpos(sf::Vector2f pos) {
btspr.setPosition(pos);
sf::Vector2f offset;
txt.setPosition(pos + offset);
}
void draw(sf::RenderWindow &rw) {
rw.draw(txt);
if (btspr.getGlobalBounds().contains(sf::Vector2f(m.getPosition())))
btspr.setTexture(btctex);
else
btspr.setTexture(bttex);
rw.draw(btspr);
rw.draw(txt);
}
bool clicked() {
if ((btspr.getGlobalBounds().contains(sf::Vector2f(m.getPosition()))) && m.isButtonPressed)
return true;
return false;
}
sf::Sprite getSprite() {
return btspr;
}
};
class mainmenu {
private:
sf::Texture backtex;
sf::Sprite background;
sf::RenderWindow menuscreen;
button play;
button exit;
//button play("play", sf::Vector2f(0.f, 10.f));
//button exit("exit", sf::Vector2f(0.f, 20.f));
public:
mainmenu():menuscreen(sf::VideoMode(400, 800), "menu") {
backtex.loadFromFile("C:/Users/Andreas/source/repos/jumpnrunSFML/Debug/Media/kp.jpg");
background.setTexture(backtex);
play.settxt("play"); play.setpos(sf::Vector2f(25.f, 50.f));
exit.settxt("exit"); exit.setpos(sf::Vector2f(25.f, 200.f));
}
void run() {
while (menuscreen.isOpen()) {
if (play.clicked()) {
menuscreen.close();
return;
}
if (exit.clicked()) {
exit;
}
menuscreen.clear();
menuscreen.draw(background);
play.draw(menuscreen);
exit.draw(menuscreen);
menuscreen.display();
}
}
};
main:
#include "game.h"
#include "menus.h"
int main()
{
mainmenu m; //menü
m.run(); //menü
return 0;
}
I hope somebody can help me. And yes, sorry for ugly code. I'm just playing around.