Use buttons.pressed/released for examples
diff --git a/examples/profiler-test/profiler-test.cpp b/examples/profiler-test/profiler-test.cpp index 93af4e3..66df80e 100644 --- a/examples/profiler-test/profiler-test.cpp +++ b/examples/profiler-test/profiler-test.cpp
@@ -83,24 +83,21 @@ void render(uint32_t time) { static Point ptMiddle(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); - static uint32_t lastButtons = 0; //static ProfilerProbe *pAwayRenderProbe = g_profiler.AddProbe("AwayFromRender"); //pAwayRenderProbe->StoreElapsedUs(true); - uint32_t changedButtons = buttons ^ lastButtons; - - bool button_a = buttons & changedButtons & Button::A; - bool button_b = buttons & changedButtons & Button::B; - bool button_x = buttons & changedButtons & Button::X; - bool button_y = buttons & changedButtons & Button::Y; - bool button_up = buttons & changedButtons & Button::DPAD_UP; - bool button_down = buttons & changedButtons & Button::DPAD_DOWN; - bool button_left = buttons & changedButtons & Button::DPAD_LEFT; - bool button_right = buttons & changedButtons & Button::DPAD_RIGHT; - bool button_home = buttons & changedButtons & Button::HOME; + bool button_a = buttons.pressed & Button::A; + bool button_b = buttons.pressed & Button::B; + bool button_x = buttons.pressed & Button::X; + bool button_y = buttons.pressed & Button::Y; + bool button_up = buttons.pressed & Button::DPAD_UP; + bool button_down = buttons.pressed & Button::DPAD_DOWN; + bool button_left = buttons.pressed & Button::DPAD_LEFT; + bool button_right = buttons.pressed & Button::DPAD_RIGHT; + bool button_home = buttons.pressed & Button::HOME; if(button_up && (g_uRows>1)) { @@ -158,8 +155,6 @@ g_profiler.log_probes(); } - lastButtons = buttons; - g_pRenderProbe->start(); // clear screen
diff --git a/examples/scrolly-tile/scrolly-tile.cpp b/examples/scrolly-tile/scrolly-tile.cpp index 1a08302..4fedac6 100644 --- a/examples/scrolly-tile/scrolly-tile.cpp +++ b/examples/scrolly-tile/scrolly-tile.cpp
@@ -492,11 +492,6 @@ } void update(uint32_t time_ms) { - static uint16_t last_buttons = 0; - uint16_t changed = buttons ^ last_buttons; - uint16_t pressed = changed & buttons; - uint16_t released = changed & ~buttons; - int32_t water_dist = player_position.y - (SCREEN_H - water_level); if (water_dist < 0) { water_dist = 0; @@ -506,38 +501,36 @@ #endif if (game_state == enum_state::menu) { - if(pressed & Button::B) { + if(buttons.pressed & Button::B) { new_game(); } - else if(pressed & Button::DPAD_UP) { + else if(buttons.pressed & Button::DPAD_UP) { current_random_source = RANDOM_TYPE_PRNG; new_level(); } - else if(pressed & Button::DPAD_DOWN) { + else if(buttons.pressed & Button::DPAD_DOWN) { current_random_source = RANDOM_TYPE_HRNG; new_level(); } - else if(pressed & Button::DPAD_RIGHT) { + else if(buttons.pressed & Button::DPAD_RIGHT) { if(current_random_source == RANDOM_TYPE_PRNG) { current_random_seed++; new_level(); } } - else if(pressed & Button::DPAD_LEFT) { + else if(buttons.pressed & Button::DPAD_LEFT) { if(current_random_source == RANDOM_TYPE_PRNG) { current_random_seed--; new_level(); } } - last_buttons = buttons; return; } if(game_state == enum_state::dead){ - if(pressed & Button::B) { + if(buttons.pressed & Button::B) { game_state = enum_state::menu; } - last_buttons = buttons; return; } @@ -583,7 +576,7 @@ } if(player_jump_count){ - if(pressed & Button::A) { + if(buttons.pressed & Button::A) { if(player_state == wall_left || player_state == wall_right || player_state == near_wall_left @@ -668,8 +661,6 @@ } for_each_tile(collide_player_ud, (void *)&tile_offset); } - - last_buttons = buttons; } void render_summary() {
diff --git a/examples/text/text.cpp b/examples/text/text.cpp index 7771895..80dfc33 100644 --- a/examples/text/text.cpp +++ b/examples/text/text.cpp
@@ -3,7 +3,6 @@ using namespace blit; bool variable_width = true; -uint32_t prev_buttons = buttons; TextAlign alignment = TextAlign::top_left; std::string alignment_to_string(TextAlign alignment) { @@ -77,7 +76,7 @@ } void update(uint32_t time) { - if ((prev_buttons & Button::A) && !(buttons & Button::A)) + if (buttons.released & Button::A) variable_width = !variable_width; alignment = TextAlign::top_left; @@ -95,6 +94,4 @@ else if (!(buttons & Button::DPAD_LEFT)) { alignment = (TextAlign)(alignment | TextAlign::center_h); } - - prev_buttons = buttons; }
diff --git a/examples/voxel/voxel.cpp b/examples/voxel/voxel.cpp index 5464c73..ced7c47 100644 --- a/examples/voxel/voxel.cpp +++ b/examples/voxel/voxel.cpp
@@ -233,7 +233,6 @@ void update(uint32_t time_ms) { static uint16_t tick = 0; - static uint32_t last_buttons = 0; tick++; @@ -283,13 +282,11 @@ } } - if(!(buttons & A) && (last_buttons & A)) { + if(buttons.released & A) { terrain_index++; if(terrain_index > 4) { terrain_index = 1; } load_map(); } - - last_buttons = buttons; } \ No newline at end of file