redesign FPS counter

Sun, 11 Aug 2024 16:29:09 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 11 Aug 2024 16:29:09 +0200
changeset 70
81a089a47eff
parent 69
86d545f490e4
child 71
baa73a0be3ce

redesign FPS counter

test/snake.c file | annotate | diff | comparison | revisions
--- 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);
 }
 

mercurial