42 if (fps != last_fps) { |
42 if (fps != last_fps) { |
43 last_fps = fps; |
43 last_fps = fps; |
44 asc_text_printf(node, "%"PRIu64" FPS", fps); |
44 asc_text_printf(node, "%"PRIu64" FPS", fps); |
45 } |
45 } |
46 } |
46 } |
47 } |
|
48 |
|
49 static void create_fps_counter(void) { |
|
50 asc_font(ASC_FONT_REGULAR, 24); |
|
51 asc_ink_rgb(255, 0, 0); |
|
52 AscSceneNode* node = asc_text( .x = 10, .y = 10 ); |
|
53 asc_scene_add_behavior(node, update_fps_counter); |
|
54 asc_add_ui_node(node); |
|
55 } |
|
56 |
|
57 static void update_score_counter(AscSceneNode *node) { |
|
58 // tie to bottom right of the screen |
47 // tie to bottom right of the screen |
59 if (asc_active_window->resized) { |
48 if (asc_test_flag(node->flags, ASC_SCENE_NODE_GRAPHICS_UPDATED) |
|
49 || asc_active_window->resized) { |
60 asc_vec2i bottom_right = asc_active_window->dimensions; |
50 asc_vec2i bottom_right = asc_active_window->dimensions; |
61 asc_vec2i scale = asc_get_scale2d(node); |
51 asc_vec2i scale = asc_get_scale2d(node); |
62 asc_set_position2d( |
52 asc_set_position2d( |
63 node, |
53 node, |
64 bottom_right.x - scale.width - 10, |
54 bottom_right.x - scale.width - 10, |
65 bottom_right.y - scale.height - 10 |
55 bottom_right.y - scale.height - 10 |
66 ); |
56 ); |
67 } |
57 } |
68 } |
58 } |
69 |
59 |
|
60 static void create_fps_counter(void) { |
|
61 asc_font(ASC_FONT_REGULAR, 12); |
|
62 asc_ink_rgba(128, 128, 128, 196); |
|
63 AscSceneNode *node = asc_text(); |
|
64 asc_scene_add_behavior(node, update_fps_counter); |
|
65 asc_add_ui_node(node); |
|
66 } |
|
67 |
70 static void create_score_counter(void) { |
68 static void create_score_counter(void) { |
71 asc_font(ASC_FONT_BOLD, 14); |
69 asc_font(ASC_FONT_BOLD, 16); |
72 asc_ink_rgb(0, 255, 0); |
70 asc_ink_rgb(0, 255, 0); |
73 AscSceneNode* node = asc_text(.text = "Score: 0" ); |
71 AscSceneNode* node = asc_text( |
74 asc_scene_add_behavior(node, update_score_counter); |
72 .x = 10, .y = 10, |
|
73 .text = "Score: 0" |
|
74 ); |
75 asc_add_ui_node(node); |
75 asc_add_ui_node(node); |
76 } |
76 } |
77 |
77 |
78 int main(int argc, char** argv) { |
78 int main(int argc, char** argv) { |
79 asc_context_initialize(); |
79 asc_context_initialize(); |