I don't directly see a mistake, but there are a lot of questionable things in the code. Can you reproduce the problem in a
minimal and complete example? Then it would be easier to see if you missed something obvious.
Maybe some tips regarding the use of Thor:
- You can directly use ActionMap::update() instead of clearEvents() and pushEvent()
- I don't see the point of your CEventManager, all it does is forwarding calls to thor::ActionMap.
And some general C++ tips:
if (m_usingTexture)
{
if (m_sprite.getGlobalBounds().contains(x, y))
return true;
}
else if (!m_usingTexture)
{
if (m_text.getGlobalBounds().contains(x, y))
return true;
}
return false;
This can be simplified a lot:
if (m_usingTexture)
return m_sprite.getGlobalBounds().contains(x, y);
else
return m_text.getGlobalBounds().contains(x, y);
The same applies to
checkIfMouseClicked().
const bool CButton::checkIfMouseHovered(const float x, const float y) const
Don't overuse
const. Only the last
const is meaningful, the other three don't improve const-correctness. See
here for detailed explanation.
m_game.m_gameGUI.update(...);
It looks like the class of
m_game is badly encapsulated, you shouldn't need to access its members directly. Maybe provide functions to hide the members.
void pushEvent(sf::Event& event) { m_eventMap.pushEvent(event); }
Since the parameter is not changed in the function, prefer using a reference to const:
const sf::Event& event.
CEventManager();
~CEventManager();
Defining constructor and destructor is not necessary, only do it if you need them. The rule of three (or five in C++11) should also be considered.
class CEventManager { enum EC_Events {...}; };
CEventManager::EC_Events::m_leftMouseButtonClicked
Accessing an enumerator via scope of the enum is unusual (in C++03 forbidden), since they are spread into the surrounding scope.
CEventManager::m_leftMouseButtonClicked would be enough. But I don't think the
m_ prefix is appropriate here; enumerators are constants, not member variables.
In general, the C prefix comes from an ancient idea (which was already wrong at that time) and shouldn't be used. See
here for more information.