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

Author Topic: Input problem  (Read 3015 times)

0 Members and 1 Guest are viewing this topic.

neos300

  • Newbie
  • *
  • Posts: 6
    • MSN Messenger - omgborg@gmail.com
    • View Profile
Input problem
« on: October 03, 2010, 04:57:34 pm »
So I'm porting my engine from SDL to SFML and I'm having some trouble porting my input system.
Input.h
Code: [Select]

#ifndef BULLWHIP_INPUT_H
#define BULLWHIP_INPUT_H
#include <SFML/Graphics.hpp>

class bc_Input
{
    public:
        bc_Input();
        bool bm_KeyHit(sf::Key::Code key);
        bool bm_KeyDown(sf::Key::Code key);
        int bm_MouseX();
        int bm_MouseY();
        void bm_init(sf::RenderWindow& app);
    private:
        sf::RenderWindow& App;
        sf::Input& bv_input;
};

#endif


Input.cpp
Code: [Select]


#include "Input.h"

bool bc_Input::bm_KeyDown(sf::Key::Code key)
{
    return bv_input.IsKeyDown(key)
}

bool bc_Input::bm_KeyHit(sf::Key::Code key)
{
    sf::Event event;
    while(App.GetEvent(event) && event.Type == sf::Event::KeyPressed)
    {
        switch(event.Key.Code)
        {
            case key: return true; break;
            default:
                break;
        }
    }

}

void bc_Input::bm_init(sf::RenderWindow& app)
{
    App = app;
    bv_input = App.GetInput();
}

int bc_Input::bm_MouseX()
{
    return bv_input.GetMouseX();
}

int bc_Input::bm_MouseY()
{
    return bv_input.GetMouseY();
}

bc_Input::bc_Input()
{
    bv_input = App.GetInput();
}


I get these errors:


c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.0/../../../../include/SFML/System/NonCopyable.hpp: In copy constructor 'sf::Window::Window(const sf::Window&)':
c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.0/../../../../include/SFML/System/NonCopyable.hpp:57: error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private
c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.0/../../../../include/SFML/Window/Window.hpp:56: error: within this context


c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.0/../../../../include/SFML/System/NonCopyable.hpp: In copy constructor 'sf::Input::Input(const sf::Input&)':
c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.0/../../../../include/SFML/System/NonCopyable.hpp:57: error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private
c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.0/../../../../include/SFML/Window/Input.hpp:45: error: within this context

I've got no idea why this is happening.

Lupinius

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Input problem
« Reply #1 on: October 03, 2010, 05:24:17 pm »
You can't copy windows and inputs, use pointers instead.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Input problem
« Reply #2 on: October 03, 2010, 05:27:53 pm »
Quote from: "Lupinius"
You can't copy windows and inputs, use pointers instead.
Or References! (Better because it doesn't require to change any code written with normal type and safer as they cannot be «pointing» on NULL.) :wink:
SFML / OS X developer

Canadadry

  • Hero Member
  • *****
  • Posts: 1081
    • View Profile
Input problem
« Reply #3 on: October 03, 2010, 10:53:59 pm »
I feel that your hitKey function will not work the way you want.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Input problem
« Reply #4 on: October 04, 2010, 06:55:34 am »
Quote from: "mooglwy"
I feel that your hitKey function will not work the way you want.
You're absolutely right! He should not use GetEvent here because he's going to miss in a way some events.
SFML / OS X developer

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Input problem
« Reply #5 on: October 04, 2010, 08:22:15 am »
You have to use a combination of events and Input::IsKeyDown. Example of Ctrl+X key pressed:
Code: [Select]

...
sf::Event Event;
while(Window.GetEvent(Event))
{
switch(Event.Type)
{
case sf::Event::KeyPressed:
switch(Event.Key.Code)
{
case sf::Key::X: // First we check for X pressed (when you cut something, you always push and hold Ctrl, and then you push X
if(Window.GetInput().IsKeyDown(sf::Key::LCtrl) // Now we have push X, let's check if used is holding Ctrl
{
std::cout << "Left control + X was pressed!" << std::endl;
}
break;
};
break;
}
}


Hope this helps!