# HG changeset patch # User Mike Becker # Date 1723386549 -7200 # Node ID 81a089a47effed0a19f112a9fcd1e12188abc7c3 # Parent 86d545f490e4e8444048225c1c0c898b98c0f3e8 redesign FPS counter diff -r 86d545f490e4 -r 81a089a47eff test/snake.c --- a/test/snake.c Sun Aug 11 16:28:54 2024 +0200 +++ b/test/snake.c Sun Aug 11 16:29:09 2024 +0200 @@ -44,19 +44,9 @@ asc_text_printf(node, "%"PRIu64" FPS", fps); } } -} - -static void create_fps_counter(void) { - asc_font(ASC_FONT_REGULAR, 24); - asc_ink_rgb(255, 0, 0); - AscSceneNode* node = asc_text( .x = 10, .y = 10 ); - asc_scene_add_behavior(node, update_fps_counter); - asc_add_ui_node(node); -} - -static void update_score_counter(AscSceneNode *node) { // tie to bottom right of the screen - if (asc_active_window->resized) { + if (asc_test_flag(node->flags, ASC_SCENE_NODE_GRAPHICS_UPDATED) + || asc_active_window->resized) { asc_vec2i bottom_right = asc_active_window->dimensions; asc_vec2i scale = asc_get_scale2d(node); asc_set_position2d( @@ -67,11 +57,21 @@ } } +static void create_fps_counter(void) { + asc_font(ASC_FONT_REGULAR, 12); + asc_ink_rgba(128, 128, 128, 196); + AscSceneNode *node = asc_text(); + asc_scene_add_behavior(node, update_fps_counter); + asc_add_ui_node(node); +} + static void create_score_counter(void) { - asc_font(ASC_FONT_BOLD, 14); + asc_font(ASC_FONT_BOLD, 16); asc_ink_rgb(0, 255, 0); - AscSceneNode* node = asc_text(.text = "Score: 0" ); - asc_scene_add_behavior(node, update_score_counter); + AscSceneNode* node = asc_text( + .x = 10, .y = 10, + .text = "Score: 0" + ); asc_add_ui_node(node); }