Skip to content

Commit e3687c1

Browse files
committed
Add draw_fps and draw_frame_time functions
1 parent 455f3fb commit e3687c1

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

examples/rustaceanmark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ async fn main() {
5555
);
5656
}
5757

58-
draw_text(format!("FPS: {}", get_fps()).as_str(), 0., 16., 32., WHITE);
58+
draw_fps(0., 16., 32., WHITE);
5959
draw_text(
6060
format!("Rustaceanes: {}", rustaceanes.len()).as_str(),
6161
0.,

src/time.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
//! Cross platform system time access and FPS counters.
22
3-
use crate::get_context;
3+
use crate::{color::Color, get_context, text::draw_text};
4+
5+
/// Draws the current FPS on the screen.
6+
pub fn draw_fps(x: f32, y: f32, font_size: f32, color: Color) {
7+
draw_text(&format!("FPS: {}", get_fps()), x, y, font_size, color);
8+
}
49

510
/// Returns current FPS
611
pub fn get_fps() -> i32 {
@@ -9,6 +14,17 @@ pub fn get_fps() -> i32 {
914
(1. / context.frame_time) as i32
1015
}
1116

17+
/// Draws the duration in seconds of the last frame drawn on the screen.
18+
pub fn draw_frame_time(x: f32, y: f32, font_size: f32, color: Color) {
19+
draw_text(
20+
&format!("Frame Time: {}", get_frame_time() * 1000.),
21+
x,
22+
y,
23+
font_size,
24+
color,
25+
);
26+
}
27+
1228
/// Returns duration in seconds of the last frame drawn
1329
pub fn get_frame_time() -> f32 {
1430
let context = get_context();

0 commit comments

Comments
 (0)