问题:
我希望在点击鼠标左键时随时更改我的角色。如果我按住按钮,它会不断更改动画,但我并不需要。我希望动画只能改变一次。我试着做这样的事情:
if (csdl_setup->GetMainEvent()->type == SDL_MOUSEBUTTONDOWN) {
if (csdl_setup->GetMainEvent()->button.button == SDL_BUTTON_LEFT) {
LeftMouseClicked = true;
}
}
if (LeftMouseClicked == true) {
LeftMouseClicked = false;
bob->PlayAnimation(0, 1, 1, 1);
}
但它不起作用。有什么想法吗?
答案 0 :(得分:1)
使用两组变量,一组用于是否保持按钮,另一组用于是否在当前帧中按下按钮。
LeftMouseClicked = false ; //is set to false every frame
if (csdl_setup->GetMainEvent()->type == SDL_MOUSEBUTTONDOWN) {
if (csdl_setup->GetMainEvent()->button.button == SDL_BUTTON_LEFT) {
if( LeftMouseHeld == false ) {
LeftMouseClicked = true ;
}
LeftMouseHeld = true;
}
}
if (LeftMouseClicked == true) {
bob->PlayAnimation(0, 1, 1, 1);
}