Hello, i have a question i follow the Tutorial "manage for different Screens" on github. Now i wanna i build in a RectangleShape (btn1), who will used for a touch button to cgange on another screen, how i can handld this, here is my code:
class screen_1: public cscreen {
public:
screen_1(void);
virtual int Run(sf::RenderWindow &App);
void btn(sf::RenderWindow &App);
private:
sf::RectangleShape btn1;
sf::FloatRect btn1Rect;
};
screen_1::screen_1(void){
btn1.setSize(sf::Vector2f(500, 100));
btn1.setPosition(sf::Vector2f(400, 500));
btn1.setFillColor(sf::Color::Red);
}
void screen_1::btn(sf::RenderWindow &App){
sf::Vector2i pixelPos = sf::Touch::getPosition(0, App);
sf::Vector2f worldPos = App.mapPixelToCoords(pixelPos);
btn1Rect = btn1.getGlobalBounds();
if(btn1Rect.contains(worldPos)){
screen_2::Run(); //dont work :(
}
int screen_1::Run(sf::RenderWindow &App){
sf::Event event;
bool Running = true;
while (Running) {
while (App.pollEvent(event))
{
if (event.type == sf::Event::Closed) {
return (-1);
}
}
}
App.clear(sf::Color(25, 200, 30));
App.draw(btn1);
App.display();
}
return (-1);
}