-
Notifications
You must be signed in to change notification settings - Fork 912
olc::Sprite
A class that represents a 2D array of olc::Pixel in the form of an image. As Pixels can be transparent, these images can be used as Sprites in games. Fundamentally the PixelGameEngine uses Portable Network Graphics images (.png files) as its primary source of artwork.
Sprites can also be created without any content, i.e. they are just blank images of a defined width and height. These can be used as targets for all of the PixelGameEngine draw calls. This means you can render things to off-screen Sprite buffers for clever rendering effects. The PixelGameEngine will create a default Sprite of the dimensions of the desired screen size, this sprite is used as the primary screen buffer.
Sprites are defined with top left being (0,0) and bottom right being (width, height). Once a sprite is created it cannot be resized. It is recommended to create sprites on the heap to ensure the required libraries are loaded to handle PNG image formats.
NOTE! Currently on Windows olc::Sprites cannot be constructed in the constructor of any olc::PixelGameEngine derived class. The GDI Subsystem for loading PNG files needs to start before sprites can be loaded, so its important to only load sprites during or after OnUserCreate(). This restriction does not apply to other OS, but keep it in mind if you want your program to remain cross platform.
Width of Sprite in olc::Pixels
Height of Sprite in olc::Pixels
Default constructor
Constructor that loads a Portable Network Graphics file specified by sImageFile. If the image file is invalid the sprite is dimensionless.
Constructor that creates a blank Sprite with w by h olc::Pixels, defaulted to olc::BLACK
Default destructor clears memory allocated by the Sprite's constructor
Loads a Portable Network Graphics file specified by sImageFile into the Sprite. If the image file is invalid the sprite is cleared and olc::FAIL is returned. If the Sprite already contained data it is erased. On a successful load, this function returns olc::OK
olc::Pixel olc::Sprite::GetPixel(int32_t x, int32_t y)
Get a copy of the olc::Pixel at location (x, y) within the Sprite. If the location lies outside of the boundary of the sprite, a olc::BLANK Pixel is returned
Replaces the olc::Pixel at location (x, y) with that specified by p. If the location lies outside of the boundary of the sprite, no pixels are set
olc::Pixel olc::Sprite::Sample(float x, float y)
Returns an equivalent pixel for the location specified by the normalised coordinate (x, y). The sample location must lie within the boundary of 0 >= x < 1.0f and 0 >= y < 1.0f. No sampling filter is applied, following a nearest neighbour protocol
olc::Pixel* olc::Sprite::GetData()
Returns a raw pointer to the memory buffer underlying the Sprite