I’m stuck on working out the correct syntax to pass the mouseX and mouseY position to my class.
My attempt was like this:
// Start the game loop
while (window.isOpen())
{
// Process events
sf::Event event;
while (window.pollEvent(event))
{
// Close window : exit
if (event.type == sf::Event::Closed) {
window.close();
}
}
// Clear screen
window.clear();
// Draw the sprite
window.draw(sprite);
window.draw(lsprite);
if(btn_quit.IsIn(sf::Event::MouseMoveEvent::x,sf::Event::MouseMoveEvent::y){
btn_quit.RenderImg(window,"button_on.png");
} else {
btn_quit.RenderImg(window,"button.png");
}
///rest of the code not relevant to this issue
This is in my class:
bool IsIn( int mouseX, int mouseY )
{
if (((mouseX > m_x) && (mouseX < m_x + m_w))
&& ((mouseY > m_y) && (mouseY < m_y + m_h ) ) ) {
return true;
} else {
return false;
}
}
I keep getting an error with the inputs of x and y how ever which says this:
error C2597: illegal reference to non-static member 'sf::Event::MouseMoveEvent::x'
error C2597: illegal reference to non-static member 'sf::Event::MouseMoveEvent::y'
You’re trying to statically access non-static member fields of a struct. You can’t do that. Try something like this: