SFML community forums
Help => General => Topic started by: buggy123 on December 16, 2009, 06:11:01 am
-
I'm getting this error
error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const sf::Input' (or there is no acceptable conversion)
C:\Documents and Settings\SFML-1.5\include\SFML/Window/Input.hpp(129): could be 'sf::Input &sf::Input::operator =(const sf::Input &)'
while trying to match the argument list '(const sf::Input, const sf::Input)'
while trying to run this line
Input.user_input = Game.App.GetInput();
Here's my class and constructor
class CInput
{
public:
const sf::Input& user_input;
CInput(sf::RenderWindow &app) : user_input(app.GetInput())
{
};
};
what's going wrong here
-
A reference must be initialized (bound to a variable) at declaration time, you can't make a reference point at another variable after that, unlike pointers.
But that's what you do, so why do you need to assign it again after construction? Do you want to bind it to the input of a different window?
-
Hmm odd. I'm having some problems. The input seems like it's not updating.
Here's my input class
class CInput
{
public:
const sf::Input& user_input;
struct Mouse
{
int mouse_x;
int mouse_y;
bool lmb;
bool rmb;
} mouse;
struct Keyboard
{
bool esc;
} keyboard;
void update_keyboard(void)
{
keyboard.esc = user_input.IsKeyDown(sf::Key::Escape);
};
void update_mouse(void)
{
mouse.mouse_x = user_input.GetMouseX();
mouse.mouse_y = user_input.GetMouseY();
mouse.lmb = user_input.IsMouseButtonDown(sf::Mouse::Left);
mouse.rmb = user_input.IsMouseButtonDown(sf::Mouse::Right);
};
CInput(sf::RenderWindow &app) : user_input(app.GetInput())
{
};
private:
};
CInput Input(Game.App);
And my main loop
while(Game.game_state == Game.Menu)
{
Input.update_mouse();
Input.update_keyboard();
if(Input.keyboard.esc)
{
Game.exit();
}
std::cout << Input.mouse.mouse_x << std::endl;
std::cout << Input.mouse.mouse_y << std::endl;
Game.App.Clear();
Game.App.Display();
}
It enters the loops but it seems like the update_mouse and update_keyboard functions is not working. The console writes 0 and when I press escape key nothing happens >_<
I'm guessing it has to do something with the user_input being a reference but I'm not sure
-
Can you show a complete source code?
-
You don't call sf::Window::GetEvent() ?
-
I'm not using events so I'm not calling GetEvent.
anyways,
int main()
{
lua_State* settings = lua.initialize_script("resource/scripts/settings.lua");
Game.initialize_app(settings, "Stick War");
while(Game.game_state == Game.Menu)
{
Input.update_mouse();
Input.update_keyboard();
if(Input.keyboard.esc)
{
Game.exit();
}
std::cout << Input.mouse.mouse_x << std::endl;
std::cout << Input.mouse.mouse_y << std::endl;
Game.App.Clear();
Game.App.Display();
}
Game.exit();
}
and the CGame class
class CGame: public CBase
{
public:
sf::RenderWindow App;
int game_state;
enum GameState{
Menu,
Setup,
Ingame
};
//create window
int initialize_app(lua_State* L, std::string app_name)
{
set_fullscreen(L);
if(fullscreen)
{
App.Create(sf::VideoMode(1024, 768, 32), app_name, sf::Style::Fullscreen);
}
else
{
App.Create(sf::VideoMode(1024, 768, 32), app_name);
}
return 0;
};
//call when app is closed
int exit(void)
{
App.Close();
return 0;
};
private:
int set_fullscreen(lua_State* L)
{
fullscreen = CScript::lua_retreive_boolean(L, "Fullscreen");
return 0;
};
bool fullscreen;
};
This is probably horrible coding, but please bear with me, as I'm still a beginner
-
Doesn't Input depend on Event?
Edit: I'm probably wrong, it's late. :)
-
Ohhhh I see. So the Input class cannot be on it's own. Got it
Thanks :D
-
Yes you're right actually, sf::Input relies on events and events are handled after a call to GetEvent ;)