I'm starting out writing a game in C++ and SFML, I have a lot of experience writing business software for servers in C# but very little experience in C++ and none in game development.
I have tried to draw a bouncing square to acquaint myself with C++, SFML and VS2012 and I got it to work, but it works funny. It stalls sometimes and the square that I'm jumping sometimes gains momentum from hitting the ground. What's the problem with my code?
void Square::Update(float elapsedTime)
{
sf::Vector2f currentPosition = _sprite.getPosition();
_velocity.y+=elapsedTime*GRAVITY;
currentPosition.x+=_velocity.x;
currentPosition.y+=_velocity.y;
if (currentPosition.y + _velocity.y>=Game::SCREEN_HEIGHT)
{
//_sprite.setPosition(_sprite.getPosition().x,0);
_velocity.y = std::abs(_velocity.y)*-0.95;
}
_sprite.setPosition(currentPosition);
}