pub struct Spritesheet { /* private fields */ }Expand description
Holds a texture for rendering.
This struct is safe to clone in order to use elsewhere: the only
data held by this struct is a handle to the internal draw
call. Currently, it is not possible to delete draw calls, and the
only way to create a new one is by using the
SpritesheetBuilder.
§Example
let mut ctx = fae::Context::new();
use fae::SpritesheetBuilder;
// Creating the spritesheet:
let spritesheet = SpritesheetBuilder::default()
.image(an_image)
.alpha_blending(false)
.build(&mut ctx);
// Later, in rendering code:
let mut ctx = ctx.start_frame(width, height, dpi_factor);
spritesheet.draw(&mut ctx)
.coordinates((100.0, 100.0, 16.0, 16.0))
.texture_coordinates((0, 0, 16, 16))
.finish();Implementations§
Source§impl Spritesheet
impl Spritesheet
Sourcepub fn draw<'a, 'b>(
&'b self,
ctx: &'a mut GraphicsContext<'_>,
) -> Sprite<'a, 'b>
pub fn draw<'a, 'b>( &'b self, ctx: &'a mut GraphicsContext<'_>, ) -> Sprite<'a, 'b>
Creates a Sprite struct, a builder struct which defines the
action “draw a sprite from this spritesheet onto the screen.”
To “execute” the builder, call
finish(). The parameters
are set using the builder
pattern.
§Optimization tips
-
If possible, make your textures without using alpha values between 1 and 0 (ie. use only 100% and 0% opacity), and disable
alpha_blendinginSpritesheetBuilder. These kinds of sprites can be drawn much more efficiently when it comes to overdraw. -
If
alpha_blendingis disabled, draw the sprites in front first. This way you’ll avoid rendering over already drawn pixels. If you’re rendering lots of sprites, this is a good place to start optimizing.- Note: if
alpha_blendingis enabled, the you should draw the sprites in the back first, to ensure correct rendering.
- Note: if
Sourcepub fn upload_texture_region<R: Into<Rect>>(
&self,
ctx: &mut GraphicsContext<'_>,
region: R,
image: &Image,
) -> bool
pub fn upload_texture_region<R: Into<Rect>>( &self, ctx: &mut GraphicsContext<'_>, region: R, image: &Image, ) -> bool
Upload an image into the specified region in the spritesheet.
As the inner values of region will be floored before use, it
is recommended to use a (i32, i32, i32, i32) as the region
parameter to ensure expected behavior.
If the width and height of region and image don’t match,
or the region isn’t completely contained within the texture,
this function will do nothing and return false.
See also:
Image::with_null_texture.
Sourcepub fn resize_texture(
&self,
ctx: &mut GraphicsContext<'_>,
new_width: i32,
new_height: i32,
) -> bool
pub fn resize_texture( &self, ctx: &mut GraphicsContext<'_>, new_width: i32, new_height: i32, ) -> bool
Resize the spritesheet texture to a new width and height, which must be equal or greater than the original dimensions. The previous contents of the texture are preserved in the origin corner of the texture.
If new_width is less than the current width, or new_height
is less than the current height, this function will do nothing
and return false.
See also:
Spritesheet::upload_texture_region.
Trait Implementations§
Source§impl Clone for Spritesheet
impl Clone for Spritesheet
Source§fn clone(&self) -> Spritesheet
fn clone(&self) -> Spritesheet
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more