1
Graphics / Mouse input with sf::View
« on: January 02, 2015, 05:34:42 pm »
Hello,
I was designing my game menu. I wanted to add slide effect between menu "states", so i used sf::View, and moved it with move() function to show the actual menu state. So for example when you click "options" in menu the view moves until it reaches coordinates where options are drawn. It was a good idea, but then i had to use mouse input. And now mouse is like x: 400 y: 500 and button is like x: 1400 and y: 1500 and because of sf::View it looks like the mouse is over button. Is it possible to make menu like that without moving every single item? Or maybe i can just fix the sf::View thing. Here's the code:
I was designing my game menu. I wanted to add slide effect between menu "states", so i used sf::View, and moved it with move() function to show the actual menu state. So for example when you click "options" in menu the view moves until it reaches coordinates where options are drawn. It was a good idea, but then i had to use mouse input. And now mouse is like x: 400 y: 500 and button is like x: 1400 and y: 1500 and because of sf::View it looks like the mouse is over button. Is it possible to make menu like that without moving every single item? Or maybe i can just fix the sf::View thing. Here's the code:
if (this->submenustate == 0 && this->ScreenView.getCenter().x != SCREEN_WIDTH / 2)
{
if (((SCREEN_WIDTH / 2) - this->ScreenView.getCenter().x) < 15)
this->ScreenView.move(-((SCREEN_WIDTH / 2) - this->ScreenView.getCenter().x), 0);
else
this->ScreenView.move(-15, 0);
}
if (this->submenustate == 1 && this->ScreenView.getCenter().x != (SCREEN_WIDTH / 2) + SCREEN_WIDTH)
{
if (this->ScreenView.getCenter().x > (SCREEN_WIDTH / 2 + SCREEN_WIDTH))
{
if (((SCREEN_WIDTH / 2 + SCREEN_WIDTH) - this->ScreenView.getCenter().x) < 15)
this->ScreenView.move(-(((SCREEN_WIDTH / 2) + SCREEN_WIDTH) - this->ScreenView.getCenter().x), 0);
else
this->ScreenView.move(-15, 0);
}
else if (this->ScreenView.getCenter().x < (SCREEN_WIDTH / 2 + SCREEN_WIDTH))
{
if (this->ScreenView.getCenter().x + 15 >(SCREEN_WIDTH / 2 + SCREEN_WIDTH))
this->ScreenView.move((SCREEN_WIDTH / 2 + SCREEN_WIDTH) - this->ScreenView.getCenter().x, 0);
else
this->ScreenView.move(15, 0);
}
}
If you need more code to help me just write what part do you need. Whole code is like 1300 lines.
{
if (((SCREEN_WIDTH / 2) - this->ScreenView.getCenter().x) < 15)
this->ScreenView.move(-((SCREEN_WIDTH / 2) - this->ScreenView.getCenter().x), 0);
else
this->ScreenView.move(-15, 0);
}
if (this->submenustate == 1 && this->ScreenView.getCenter().x != (SCREEN_WIDTH / 2) + SCREEN_WIDTH)
{
if (this->ScreenView.getCenter().x > (SCREEN_WIDTH / 2 + SCREEN_WIDTH))
{
if (((SCREEN_WIDTH / 2 + SCREEN_WIDTH) - this->ScreenView.getCenter().x) < 15)
this->ScreenView.move(-(((SCREEN_WIDTH / 2) + SCREEN_WIDTH) - this->ScreenView.getCenter().x), 0);
else
this->ScreenView.move(-15, 0);
}
else if (this->ScreenView.getCenter().x < (SCREEN_WIDTH / 2 + SCREEN_WIDTH))
{
if (this->ScreenView.getCenter().x + 15 >(SCREEN_WIDTH / 2 + SCREEN_WIDTH))
this->ScreenView.move((SCREEN_WIDTH / 2 + SCREEN_WIDTH) - this->ScreenView.getCenter().x, 0);
else
this->ScreenView.move(15, 0);
}
}