diff --git a/src/color.rs b/src/color.rs index e5f4bdf7..0a6c9823 100644 --- a/src/color.rs +++ b/src/color.rs @@ -131,6 +131,25 @@ impl Color { Self::from_rgba(bytes[1], bytes[2], bytes[3], 255) } + /// Build a color from a hexadecimal u32 and an accompanying u8 alpha value. + /// + /// # Example + /// + /// ``` + /// use macroquad::prelude::*; + /// + /// let light_blue = Color::from_hex_alpha(0x3CA7D5, 0x80); + /// assert_eq!(light_blue.r, 0.23529412); + /// assert_eq!(light_blue.g, 0.654902); + /// assert_eq!(light_blue.b, 0.8352941); + /// assert_eq!(light_blue.a, 0.5019608); + /// ``` + pub fn from_hex_alpha(hex: u32, alpha: u8) -> Color { + let bytes: [u8; 4] = hex.to_be_bytes(); + + Self::from_rgba(bytes[1], bytes[2], bytes[3], alpha) + } + /// Create a vec4 of red, green, blue, and alpha components. pub fn to_vec(&self) -> glam::Vec4 { glam::Vec4::new(self.r, self.g, self.b, self.a) diff --git a/src/time.rs b/src/time.rs index cb688f3d..d53ad41e 100644 --- a/src/time.rs +++ b/src/time.rs @@ -1,4 +1,4 @@ -//! Cross platform system time access and FPS counters. +//! Cross-platform system time access and FPS counters. use crate::get_context; @@ -9,7 +9,7 @@ pub fn get_fps() -> i32 { (1. / context.frame_time) as i32 } -/// Returns duration in seconds of the last frame drawn +/// Returns duration in seconds of the last frame drawn, the "delta time." pub fn get_frame_time() -> f32 { let context = get_context(); @@ -23,7 +23,7 @@ pub fn get_frame_time() -> f32 { /// Returns elapsed wall-clock time in seconds since start /// /// Note that as real world time progresses during computation, -/// the value returned will change. Therefore if you want +/// the value returned will change. Therefore, if you want /// your game logic update to happen at the same *in-game* time /// for all game objects, you should call this function once /// save the value and reuse it throughout your code.