I'm trying to load images and return them so then my class can load the images. But I'm complete confused how it works.
This is my function:
[source lang="cpp"]void menuPreload(std::string theme,std::string theme_on,sf::Texture &button, sf::Texture &button_on,int &width,int &height){ std::string img; std::string img_on; img = theme; img_on = theme_on; if (!button.loadFromFile(img)){ exit(4); } if (!button_on.loadFromFile(img_on)){ exit(5); } sf::Sprite sprite(button); width = sprite.getLocalBounds().width; height = sprite.getLocalBounds().height; }[/source]
I think call it like this in my main function:
[source lang="cpp"] sf::Texture button; sf::Texture button_on; int width; int height; menuPreload(config["Button"],config["Button_On"],button,button_on,width,height); [/source]
After i have preloaded the images i call my class to load the button like this:
[source long="cpp"]//before loopButton btn_quit(window.getSize().y/2, 200,width,height);//inside my loopbtn_quit.RenderBttn(window,mouseX,mouseY,button,button_on);[/source]
So far i think this is correct... but then in my class i have:
[source lang="cpp"]class Button { private: int m_x, m_y; int m_w, m_h; public: Button(int x, int y, int m_w, int m_h) { m_y = y; m_x = x - m_w/2; } bool IsIn( int mouseX, int mouseY ) { exit(m_h); if (((mouseX > m_x) && (mouseX < m_x + m_w)) && ((mouseY > m_y) && (mouseY < m_y + m_h ) ) ) { return true; } else { return false; } } void RenderBttn(sf::RenderWindow &destination,int mouseX, int mouseY,sf::Texture button, sf::Texture button_on) { sf::Sprite result(IsIn(mouseX,mouseY) ? button_on : button); result.setPosition( m_x , m_y); destination.draw(result); }};[/source]
The issue is when the mouse is over the button it doesn't change, m_w seems to be not set or incorrect. Am i on the right lines here... my brain is about to explode ...