Made a basic movement system from scratch using a switch rather than if statements, sprite is drawn but does not move.
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
// Checks the event
switch (event.type){
// if you press close, close the window
case event.Closed: {
window.close();
break;}
case event.KeyPressed: {
switch (event.key.code){
case Keyboard::A:{
playerleft = true;
break;}
case Keyboard::D:{
playerright = true;
break;}
default:
break; }
}
case event.KeyReleased: {
switch (event.key.code){
case Keyboard::A:{
playerleft = false;
break;}
case Keyboard::D:{
playerright = false;
break;}
default:
break; }
default:
break;
}
} // closes the check event switch
} // closes the event check loop
Clock clock;
float alphaTime = clock.restart().asSeconds();
if (playerleft == true){
xvel = -1;
}
if (playerright == true){
xvel = 1;
}
if (xvel > 0){
xvel =- 1*alphaTime;
}
if (xvel < 0){
xvel =+ 1*alphaTime;
}
player.move(Vector2f(0.f+xvel,0.f+yvel));
window.clear();
window.draw(player);
window.display();
} // closes the window open loop
New to c++/sfml so sorry if this is a stupid question.