Skip to content

Commit

Permalink
Add draw_fps and draw_frame_time functions
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohq committed Oct 26, 2024
1 parent 455f3fb commit e3687c1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/rustaceanmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async fn main() {
);
}

draw_text(format!("FPS: {}", get_fps()).as_str(), 0., 16., 32., WHITE);
draw_fps(0., 16., 32., WHITE);
draw_text(
format!("Rustaceanes: {}", rustaceanes.len()).as_str(),
0.,
Expand Down
18 changes: 17 additions & 1 deletion src/time.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
//! Cross platform system time access and FPS counters.
use crate::get_context;
use crate::{color::Color, get_context, text::draw_text};

/// Draws the current FPS on the screen.
pub fn draw_fps(x: f32, y: f32, font_size: f32, color: Color) {
draw_text(&format!("FPS: {}", get_fps()), x, y, font_size, color);
}

/// Returns current FPS
pub fn get_fps() -> i32 {
Expand All @@ -9,6 +14,17 @@ pub fn get_fps() -> i32 {
(1. / context.frame_time) as i32
}

/// Draws the duration in seconds of the last frame drawn on the screen.
pub fn draw_frame_time(x: f32, y: f32, font_size: f32, color: Color) {
draw_text(
&format!("Frame Time: {}", get_frame_time() * 1000.),
x,
y,
font_size,
color,
);
}

/// Returns duration in seconds of the last frame drawn
pub fn get_frame_time() -> f32 {
let context = get_context();
Expand Down

0 comments on commit e3687c1

Please sign in to comment.