refactor(输入处理): 将SDL控制器按钮替换为引擎定义的GamepadButton枚举
统一使用引擎定义的GamepadButton枚举来处理游戏手柄输入,提高代码可维护性并减少对SDL的直接依赖
This commit is contained in:
parent
1f10ce999c
commit
c6a5557d89
|
|
@ -118,20 +118,20 @@ void PlayScene::onUpdate(float dt) {
|
|||
auto& input = app.input();
|
||||
|
||||
// B 键返回主菜单
|
||||
if (input.isButtonPressed(SDL_CONTROLLER_BUTTON_B)) {
|
||||
if (input.isButtonPressed(extra2d::GamepadButton::B)) {
|
||||
app.scenes().replaceScene(
|
||||
extra2d::makePtr<StartScene>(), extra2d::TransitionType::Fade, 0.2f);
|
||||
return;
|
||||
}
|
||||
|
||||
// Y 键重开
|
||||
if (input.isButtonPressed(SDL_CONTROLLER_BUTTON_Y)) {
|
||||
if (input.isButtonPressed(extra2d::GamepadButton::Y)) {
|
||||
setLevel(g_CurrentLevel);
|
||||
return;
|
||||
}
|
||||
|
||||
// X键直接切换音效
|
||||
if (input.isButtonPressed(SDL_CONTROLLER_BUTTON_X)) {
|
||||
if (input.isButtonPressed(extra2d::GamepadButton::X)) {
|
||||
g_SoundOpen = !g_SoundOpen;
|
||||
AudioManager::instance().setEnabled(g_SoundOpen);
|
||||
updateSoundIcon();
|
||||
|
|
@ -139,22 +139,22 @@ void PlayScene::onUpdate(float dt) {
|
|||
}
|
||||
|
||||
// A 键执行选中的菜单项
|
||||
if (input.isButtonPressed(SDL_CONTROLLER_BUTTON_A)) {
|
||||
if (input.isButtonPressed(extra2d::GamepadButton::A)) {
|
||||
executeMenuItem();
|
||||
return;
|
||||
}
|
||||
|
||||
// 方向键移动
|
||||
if (input.isButtonPressed(SDL_CONTROLLER_BUTTON_DPAD_UP)) {
|
||||
if (input.isButtonPressed(extra2d::GamepadButton::DPadUp)) {
|
||||
move(0, -1, 1);
|
||||
flush();
|
||||
} else if (input.isButtonPressed(SDL_CONTROLLER_BUTTON_DPAD_DOWN)) {
|
||||
} else if (input.isButtonPressed(extra2d::GamepadButton::DPadDown)) {
|
||||
move(0, 1, 2);
|
||||
flush();
|
||||
} else if (input.isButtonPressed(SDL_CONTROLLER_BUTTON_DPAD_LEFT)) {
|
||||
} else if (input.isButtonPressed(extra2d::GamepadButton::DPadLeft)) {
|
||||
move(-1, 0, 3);
|
||||
flush();
|
||||
} else if (input.isButtonPressed(SDL_CONTROLLER_BUTTON_DPAD_RIGHT)) {
|
||||
} else if (input.isButtonPressed(extra2d::GamepadButton::DPadRight)) {
|
||||
move(1, 0, 4);
|
||||
flush();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ void SuccessScene::onUpdate(float dt) {
|
|||
auto& input = app.input();
|
||||
|
||||
// A键确认返回主菜单
|
||||
if (input.isButtonPressed(SDL_CONTROLLER_BUTTON_A)) {
|
||||
if (input.isButtonPressed(extra2d::GamepadButton::A)) {
|
||||
auto& scenes = extra2d::Application::instance().scenes();
|
||||
scenes.popScene(extra2d::TransitionType::Fade, 0.2f);
|
||||
scenes.popScene(extra2d::TransitionType::Fade, 0.2f);
|
||||
|
|
|
|||
Loading…
Reference in New Issue