Original Post
Hi hi,
I'm creating a game for my portfolio and at present it's a simple sprite running around a screen (no rotations or anything implemented yet) and I'm finding a minor issue quite annoying.
If a player is holding down the up key to move vertically and then hits the right key to head right, whilst still holding down the up keupon release of the right key the sprite doesn't move upwards as you'd expect.
I can kind of see why it does what it's doing, but I can't think of a solution. Any ideas?
Here's my input function:
[source lang="cpp"]void Game::getInput()
{
sf::Event Event;
while (MyGameWindow->GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
MyGameWindow->Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
MyGameWindow->Close();
if(Event.Type == sf::Event::KeyPressed) currentKey = Event.Key.Code;
if(Event.Type == sf::Event::KeyReleased) currentKey = sf::Key::Numpad9;
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::R))
paused = false;
}
}[/source]
And then my update function:
[source lang="cpp"]void Game::update()
{
if(!paused)
{
ELAPSED_TIME = myClock.GetElapsedTime();
if (ELAPSED_TIME > FRAMERATE)
{
switch(currentKey)
{
case sf::Key::Up:
P1.MoveUp(10);
break;
case sf::Key::Down:
P1.MoveDown(10);
break;
case sf::Key::Left:
P1.MoveLeft(10);
break;
case sf::Key::Right:
P1.MoveRight(10);
break;
case sf::Key:
:
paused = true;
break;
}
myClock.Reset();
}
}
}[/source]
Cheers guys!
I'm creating a game for my portfolio and at present it's a simple sprite running around a screen (no rotations or anything implemented yet) and I'm finding a minor issue quite annoying.
If a player is holding down the up key to move vertically and then hits the right key to head right, whilst still holding down the up keupon release of the right key the sprite doesn't move upwards as you'd expect.
I can kind of see why it does what it's doing, but I can't think of a solution. Any ideas?
Here's my input function:
[source lang="cpp"]void Game::getInput()
{
sf::Event Event;
while (MyGameWindow->GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
MyGameWindow->Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
MyGameWindow->Close();
if(Event.Type == sf::Event::KeyPressed) currentKey = Event.Key.Code;
if(Event.Type == sf::Event::KeyReleased) currentKey = sf::Key::Numpad9;
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::R))
paused = false;
}
}[/source]
And then my update function:
[source lang="cpp"]void Game::update()
{
if(!paused)
{
ELAPSED_TIME = myClock.GetElapsedTime();
if (ELAPSED_TIME > FRAMERATE)
{
switch(currentKey)
{
case sf::Key::Up:
P1.MoveUp(10);
break;
case sf::Key::Down:
P1.MoveDown(10);
break;
case sf::Key::Left:
P1.MoveLeft(10);
break;
case sf::Key::Right:
P1.MoveRight(10);
break;
case sf::Key:
paused = true;
break;
}
myClock.Reset();
}
}
}[/source]
Cheers guys!