Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: delay in key presses(for movement)  (Read 3936 times)

0 Members and 1 Guest are viewing this topic.

WSPSNIPER

  • Newbie
  • *
  • Posts: 28
    • View Profile
delay in key presses(for movement)
« on: March 10, 2010, 01:54:05 am »
there is a delay in key presses, i have tried 2 different things the first one was using an input and getting a bool for the key pressed

Code: [Select]

void Player::Move(const sf::Input &input)
{
if( input.IsKeyDown( sf::Key::Up ))
{
m_yVel -= m_speed;
Animate();
}

else if(input.IsKeyDown( sf::Key::Down ))
{
m_yVel += m_speed;
Animate();
}


else if(input.IsKeyDown( sf::Key::Left ))
{
m_xVel -= m_speed;
Animate();
}

else if(input.IsKeyDown( sf::Key::Right ))
{
m_xVel += m_speed;
Animate();
}

if( input.IsKeyDown( sf::Key::A ))
weapon->Add(new Knife(m_x, m_y));
}


then i tried to do the switch statement taking an event

Code: [Select]

if(Event.Type == sf::Event::KeyPressed)
{
switch(Event.Key.Code){
case sf::Key::Up:
m_yVel -= m_speed;
Animate();
break;
case sf::Key::Down:
m_yVel += m_speed;
Animate();
break;
case sf::Key::Right:
m_xVel += m_speed;
Animate();
break;
case sf::Key::Left:
m_xVel -= m_speed;
Animate();
break;
default:
break;
}
}
if(Event.Type == sf::Event::KeyReleased)
{
switch(Event.Key.Code){
case sf::Key::Right:
m_xVel = 0;
break;
case sf::Key::Left:
m_xVel = 0;
break;
case sf::Key::Up:
m_yVel = 0;
break;
case sf::Key::Down:
m_yVel = 0;
break;
default:
break;
}
}
}


ps the first one i decrease the accel in the main eventhandling function

There is only a delay when you switch form left to right or up to down with out releasing the previous button first and it is like a 1/2 sec delay and if any of my friends play i dont want them complaining so HELP!!

 

anything