Reputation: 193
while (window.isOpen())
{
// Process events
sf::Event event;
while (window.pollEvent(event))
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))()&&accelerationx > 15;
{
accelerationx = accelerationx + 5;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))()&&accelerationx > 0;
{
accelerationx = accelerationx -5;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))()&&accelerationx > 15;
{
accelerationy = accelerationy + 5;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))()&&accelerationx > 0;
{
accelerationy = accelerationy - 5;
}
speedx = accelerationx + speedx;
speedy = accelerationy + speedy;
sprite.move(sf::Vector2f(0.f+speedx, 0.f+speedy));
}
// Clear screen
window.clear();
// Draw the sprite
window.draw(sprite);
// Update the window
window.display();
}
return EXIT_SUCCESS;
}
Returns:
error: expected primary-expression before ')' token
New to C++ and SFML so apologies if this is a stupid question. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce dui erat, blandit eget facilisis ac, euismod non metus.
Upvotes: 1
Views: 234
Reputation: 14151
Expression (condition) after the if
must be in parentheses ()
and NOT terminated by semicolon ;
.
If you have only 1 command in the if
block, you need not put it between braces {}
:
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) && accelerationx > 15)
accelerationx = accelerationx + 5;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) && accelerationx > 0)
accelerationx = accelerationx -5;
Moreover, it is nicer to use assignment operators (+=
, -=
) for increasing / decreasing values:
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) && accelerationx > 15)
accelerationx += 5;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) && accelerationx > 0)
accelerationx -= 5;
Upvotes: 1