Jump to content

Problem with App::clearMouseButtonState


photo

Recommended Posts

Hi all!

We want to check if the left mouse button was pressed once and so we use App::get()->clearMouseButtonState(App::BUTTON_LEFT) but then left mouse button is refused to work.

It's a bug or we do smth wrong?

 

Unigine version 2.7.2.1.

Link to comment
1 hour ago, silent said:

Hi Artem,

Could you please provide a sample code that you are using? Also engine startup options and defines (if any) will be interesting to see.

Thanks!

silent, I have test this on default new project without plugins (after all attempt to force to work in main project). Just I have added Unigine::App::get()->clearMouseButtonState(Unigine::App::BUTTON_LEFT) into AppWorldLogic::update().

Link to comment

Hello Artem,

That's the common pattern of using that function:

if (Unigine::App::get()->getMouseButtonState(Unigine::App::BUTTON_LEFT))
{
    Unigine::Log::message("pressed\n");
    Unigine::App::get()->clearMouseButtonState(Unigine::App::BUTTON_LEFT);
}

clearMouseButtonState is used here to log a message for every mouse button press instead of every frame when mouse button is pressed. Could you please elaborate what behaviour did you expect?

Link to comment

That's because GUI listening mouse buttons too. You could use Controls which is used for game logic exclusively.

Unigine::ControlsPtr controls = Unigine::Game::get()->getPlayer()->getControls();

if (controls->getState(Unigine::Controls::STATE_FIRE))
{
    Unigine::Log::message("pressed\n");
    controls->clearState(Unigine::Controls::STATE_FIRE);
}

Also we currently working on new input system which allows to handle keypress once in a more friendly way.

Link to comment
×
×
  • Create New...