pub struct Sprite {
pub width: usize,
pub height: usize,
/* private fields */
}Expand description
A 2D sprite consisting of glyphs and color values.
Sprites can be drawn using ConsoleGameEngine methods like draw_sprite or
draw_partial_sprite.
Fields§
§width: usizeWidth of the sprite in characters.
height: usizeHeight of the sprite in characters.
Implementations§
Source§impl Sprite
impl Sprite
Sourcepub fn new(width: usize, height: usize) -> Self
pub fn new(width: usize, height: usize) -> Self
Creates a new sprite of the given width and height.
All glyphs are initialized to PIXEL_EMPTY and all colors to FG_BLACK.
Sourcepub fn from_file(path: &str) -> Result<Self, Box<dyn Error>>
pub fn from_file(path: &str) -> Result<Self, Box<dyn Error>>
Loads a sprite from a file (by convention ending in .spr).
The file must contain width and height (u32 little-endian) followed by colors and glyphs.
Sourcepub fn save_to_file(&self, path: &str) -> Result<(), Box<dyn Error>>
pub fn save_to_file(&self, path: &str) -> Result<(), Box<dyn Error>>
Saves the sprite to a .spr file in the same format as from_file.
Sourcepub fn get_glyph(&self, x: usize, y: usize) -> u16
pub fn get_glyph(&self, x: usize, y: usize) -> u16
Returns the glyph at (x, y), or PIXEL_EMPTY if out of bounds.
Sourcepub fn get_color(&self, x: usize, y: usize) -> u16
pub fn get_color(&self, x: usize, y: usize) -> u16
Returns the color at (x, y), or FG_BLACK if out of bounds.
Sourcepub fn sample_glyph(&self, x: f32, y: f32) -> u16
pub fn sample_glyph(&self, x: f32, y: f32) -> u16
Samples the glyph at normalized coordinates (x, y) in [0.0, 1.0) space.
Wrapping occurs for coordinates outside the [0,1) range.
Sourcepub fn sample_color(&self, x: f32, y: f32) -> u16
pub fn sample_color(&self, x: f32, y: f32) -> u16
Samples the color at normalized coordinates (x, y) in [0.0, 1.0) space.
Wrapping occurs for coordinates outside the [0,1) range.