1
General / Re: Visual Studio ignores ELSE IF
« on: January 08, 2018, 02:20:49 pm »Whether you use if/else or switch is not really important, what is important, is that you need to check the event's key and not use isKeyPressed. Again read the tutorial on events, especially the big red box!
I'm so thankful to you for spending your time on me
Soo this is the very last solution that I found.
#include <SFML/Graphics.hpp>
using namespace sf;
using namespace std;
String CurrentlyAt = "Menu";
int Lal = 1;
int main()
{
RenderWindow window(VideoMode(1244, 772), "Test");
Texture TextureMenu;
TextureMenu.loadFromFile("Menu.png");
Sprite Menu(TextureMenu);
Texture TextureOptionsInMenu;
TextureOptionsInMenu.loadFromFile("1.png");
Sprite OptionsInMenu(TextureOptionsInMenu);
OptionsInMenu.setPosition(487, 293);
window.setKeyRepeatEnabled(false);
while (window.isOpen())
{
window.clear();
// Process events
Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
// window closed
case sf::Event::Closed:
window.close();
break;
// key pressed
case sf::Event::KeyPressed:
if (event.key.code == sf::Keyboard::W)
{
if (CurrentlyAt == "Menu")
{
if (Lal == 2)
{
OptionsInMenu.setPosition(487, 293);
Lal = 1;
}
else if (Lal == 1)
{
OptionsInMenu.setPosition(487, 236);
Lal = 0;
}
}
}
else if (event.key.code == sf::Keyboard::S)
{
if (CurrentlyAt == "Menu")
{
if (Lal == 0)
{
OptionsInMenu.setPosition(487, 293);
Lal = 1;
}
else if (Lal == 1)
{
OptionsInMenu.setPosition(487, 348);
Lal = 2;
}
}
}
break;
// we don't process other types of events
default:
break;
}
}
window.draw(Menu);
window.draw(OptionsInMenu);
window.display();
}
return 0;
}
using namespace sf;
using namespace std;
String CurrentlyAt = "Menu";
int Lal = 1;
int main()
{
RenderWindow window(VideoMode(1244, 772), "Test");
Texture TextureMenu;
TextureMenu.loadFromFile("Menu.png");
Sprite Menu(TextureMenu);
Texture TextureOptionsInMenu;
TextureOptionsInMenu.loadFromFile("1.png");
Sprite OptionsInMenu(TextureOptionsInMenu);
OptionsInMenu.setPosition(487, 293);
window.setKeyRepeatEnabled(false);
while (window.isOpen())
{
window.clear();
// Process events
Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
// window closed
case sf::Event::Closed:
window.close();
break;
// key pressed
case sf::Event::KeyPressed:
if (event.key.code == sf::Keyboard::W)
{
if (CurrentlyAt == "Menu")
{
if (Lal == 2)
{
OptionsInMenu.setPosition(487, 293);
Lal = 1;
}
else if (Lal == 1)
{
OptionsInMenu.setPosition(487, 236);
Lal = 0;
}
}
}
else if (event.key.code == sf::Keyboard::S)
{
if (CurrentlyAt == "Menu")
{
if (Lal == 0)
{
OptionsInMenu.setPosition(487, 293);
Lal = 1;
}
else if (Lal == 1)
{
OptionsInMenu.setPosition(487, 348);
Lal = 2;
}
}
}
break;
// we don't process other types of events
default:
break;
}
}
window.draw(Menu);
window.draw(OptionsInMenu);
window.display();
}
return 0;
}