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

Author Topic: sf::input for sfml2  (Read 3141 times)

0 Members and 2 Guests are viewing this topic.

krrice

  • Newbie
  • *
  • Posts: 26
    • View Profile
sf::input for sfml2
« on: January 12, 2012, 02:32:08 am »
I have been following the Game From Scratch tutorial and it is coded in 1.6.
I think I have everything right except the code for sf::Input I looked at the documentation and cant seem to figure it out.Here is the code, if anyone can give some info i would greatly appreciate it.

 
Code: [Select]

const sf::Input& Game::GetInput()
{
return _mainWindow.GetInput();
}



I already know that it should be keyPressed and Keyboard

Code: [Select]

void PlayerPaddle::Update(float elapsedTime)
{

if(Game::GetInput().IsKeyDown(sf::Key::Left))
{
this->_velocity-= 5.0f;
}
if(Game::GetInput().IsKeyDown(sf::Key::Right))
{
this->_velocity+= 5.0f;
}

if(Game::GetInput().IsKeyDown(sf::Key::Down))
{
this->_velocity= 0.0f;
}

if(_velocity > _maxVelocity)
this->_velocity = _maxVelocity;

if(_velocity < -_maxVelocity)
this->_velocity = -_maxVelocity;


sf::Vector2f pos = this->GetPosition();

if(pos.x  < GetSprite().GetSize().x/2
|| pos.x > (Game::SCREEN_WIDTH - GetSprite().GetSize().x/2))
{
_velocity = -_velocity; // Bounce by current velocity in opposite direction
}

GetSprite().Move(_velocity * elapsedTime, 0);
}

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
sf::input for sfml2
« Reply #1 on: January 12, 2012, 04:20:15 am »
I almost missed that one to do with input key codes because of the switch he made. :oops:  Take a look at the Game.h and Game.cpp files that are in the form of links instead of windows if the code don't work.

Not sure how to explain the input codes though, all I know is they work and what some of them do but that's about it.
I have many ideas but need the help of others to find way to make use of them.

krrice

  • Newbie
  • *
  • Posts: 26
    • View Profile
sf::input for sfml2
« Reply #2 on: January 12, 2012, 04:39:22 am »
Quote from: "StormWingDelta"
I almost missed that one to do with input key codes because of the switch he made. :oops:  Take a look at the Game.h and Game.cpp files that are in the form of links instead of windows if the code don't work.

Not sure how to explain the input codes though, all I know is they work and what some of them do but that's about it.


Thanks for the reply
Were you using 2.0 or 1.6?

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
sf::input for sfml2
« Reply #3 on: January 12, 2012, 05:15:49 am »
I'm using 1.6 because for some reason me and CMake are getting along and it isn't generating usable files for some reason.  Not sure why because everything is setup right. The only thing that is different from most people is I have my CMake on the D drive and my compiler on the C drive so that could be affecting it but I'm not sure.
I have many ideas but need the help of others to find way to make use of them.

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
sf::input for sfml2
« Reply #4 on: January 14, 2012, 05:20:42 am »
Cross posting here I suppose, but it appears the way IO is done has changed with 2.0.


Input no longer exists, and GetInput() is not longer a part of RenderWindow (which makes sense ).  Instead you use the globally available sf::Keyboard::IsKeyPressed().  Essentially the Game::GetInput() method moot.