Make Pong example "usable" on iOS

This commit is contained in:
Ceylo 2018-04-13 19:22:20 +02:00 committed by Lukas Dürrenberger
parent 5ab36271c7
commit 9f4a0c3c4f

View File

@ -111,7 +111,8 @@ int main()
} }
// Space key pressed: play // Space key pressed: play
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Space)) if (((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Space)) ||
(event.type == sf::Event::TouchBegan))
{ {
if (!isPlaying) if (!isPlaying)
{ {
@ -151,6 +152,12 @@ int main()
leftPaddle.move(0.f, paddleSpeed * deltaTime); leftPaddle.move(0.f, paddleSpeed * deltaTime);
} }
if (sf::Touch::isDown(0))
{
sf::Vector2i pos = sf::Touch::getPosition(0, window);
leftPaddle.setPosition(0.f, pos.y);
}
// Move the computer's paddle // Move the computer's paddle
if (((rightPaddleSpeed < 0.f) && (rightPaddle.getPosition().y - paddleSize.y / 2 > 5.f)) || if (((rightPaddleSpeed < 0.f) && (rightPaddle.getPosition().y - paddleSize.y / 2 > 5.f)) ||
((rightPaddleSpeed > 0.f) && (rightPaddle.getPosition().y + paddleSize.y / 2 < gameHeight - 5.f))) ((rightPaddleSpeed > 0.f) && (rightPaddle.getPosition().y + paddleSize.y / 2 < gameHeight - 5.f)))