私はこれを一日中考えようとしています。私は単純なチェックボックスを作ろうとしています。しかし、私のMOUSEBUTTONUPイベントは、マウスを動かしたり、もう一度クリックしたりするような別のイベントをトリガするまで、起動し続けます。それは、一度トリガするために私が望むすべてがあるSDL2 MOUSEBUTTONUPが1回以上トリガーする
コンソールで//If a mouse button was released
if (Sdl_Setup->GetMainEvent()->type == SDL_MOUSEBUTTONUP)
{
//If the left mouse button was pressed
if (Sdl_Setup->GetMainEvent()->button.button == SDL_BUTTON_LEFT)
{
//Get the mouse offsets
SDL_GetMouseState(&mouseX, &mouseY);
//If the mouse is over the button
if ((mouseX > Button->GetX()) && (mouseX < Button->GetX() + Button->GetWidth()) && (mouseY > Button->GetY()) && (mouseY < Button->GetY() + Button->GetHeight()))
{
//Set the button sprite
state = selected;
Button->SetCrop(GetFrameX(), GetFrameY(), state);
clicked = true;
std::cout << clicked << std::endl;
}
}
}
これますちょうどスパム1(マウスを動かすいけない場合)。私が読んだことからMOUSEBUTTONUPは一度だけイベントキューに送られることになっています
私はそれをクリックした後に停止するためにboolを追加しようとしました。ボックスをオンとオフに切り替えることができるように、boolをfalseに戻すelseステートメントを追加すると、1つではなく101010がスパムされます。私はそのような私が使用しているウィンドウやものを作り、私はそれだけで何度も何度もPollEvent()
にそれを送っていたGetMainEvent()
を呼んでいたとき、変数mainEvent
がそうそして= new SDL_Event();
ですSdl_Setup
で
//If a mouse button was released
if (Sdl_Setup->GetMainEvent()->type == SDL_MOUSEBUTTONUP)
{
//If the left mouse button was pressed
if (Sdl_Setup->GetMainEvent()->button.button == SDL_BUTTON_LEFT)
{
//Get the mouse offsets
SDL_GetMouseState(&mouseX, &mouseY);
//If the mouse is over the button
if ((mouseX > Button->GetX()) && (mouseX < Button->GetX() + Button->GetWidth()) && (mouseY > Button->GetY()) && (mouseY < Button->GetY() + Button->GetHeight()))
{
if (clicked == false)
{
//Set the button sprite
state = selected;
Button->SetCrop(GetFrameX(), GetFrameY(), state);
clicked = true;
std::cout << clicked << std::endl;
}
else
{
//Set the button sprite
state = noInteraction;
Button->SetCrop(GetFrameX(), GetFrameY(), state);
clicked = false;
std::cout << clicked << std::endl;
}
}
}
}
'Sdl_Setup-> GetMainEvent()'は最新のイベントを返します。それを「無効な」状態にリセットする方法が必要になるでしょう。 – keltar
@keltarそれでした!全く意味をなさない。ご協力いただきありがとうございます – Arkyris