Struct pixel_engine::Sprite

source ·
pub struct Sprite { /* private fields */ }
Expand description

Represent a Sprite

Implementations§

Load an rgba slice as an Sprite, will clone the slice the dimentions are in pixel

Errors

if the slice isn’t an rgba slice it will return an Err this means that slice.len() % 4 = 0 and that slice.len() = width * height * 4

Creates a subsprite on a given parent sprite The real position will be clamped to the sprite dimentions, so if the pos has some negative parts, it will be clipped, only showing the positive part. Same with if the size + pos goes outside of the sprite.

Errors

This will return an error if an subsprite already exists and that it overlaps

Creates a subsprite without any checks

Safety
  • You need to make sure there is no overlap with another subsprite
  • You need to make sure that the size is correct and fit inside the base sprites
  • You need to make sure that the area has been inserted in the area list and that the given index is the one pointing to the subsprite’s area;

This is used when using create_sub_sprite_unchecked()

Safety

Editing this could lead to overlapping subsprite so be careful when handling the list (slab) of areas.

Load an image from bytes, will clone the slice

Errors

If the slice isn’t an valid image format handled by the image crate, returns an error

Load a image file and return a Sprite object representing that image

Errors

If the file isn’t an valid image format handled by the image crate or if the file IO failed, returns an error

Create Sprite with a size of 1x1

Create Sprite with given size and Color

Create a blank Sprite with given size

Set pixel’s Color on a Sprite

Return the Color of the pixel at given coordinates, if it exist

Return the Color of the pixel at given sample This sampling will take only the fractional part of the given sample coordinates, so it is effictivly from [O; 1)

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Safety

its up to the caller to make sure that the given position is in bounds

Safety

its up to the caller to make sure that the given position is in bounds

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.