Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Sprite Class Reference

Higher-level representation of an image. More...

#include <jngl/sprite.hpp>

Public Types

enum  LoadType { NORMAL, HALF, THREADED }

Public Member Functions

 Sprite (const unsigned char *bytes, size_t width, size_t height)
 Sprite (const std::string &filename, LoadType loadType=LoadType::NORMAL)
void step () override
 Advance object's state.
void draw () const override
 Called when drawing a frame.
void draw (const ShaderProgram *shaderProgram) const
void drawScaled (float factor) const
void drawScaled (float xfactor, float yfactor, const ShaderProgram *shaderProgram=nullptr) const
 Draws the image scaled around its center by xfactor and yfactor More...
void drawClipped (float xstart, float xend, float ystart, float yend) const
void drawClipped (Vec2 start, Vec2 end) const
 Draw a cutout of the sprite. drawClipped({0, 0}, {1, 1}) would draw it normally.
void drawMesh (const std::vector< Vertex > &vertexes, const ShaderProgram *=nullptr) const
 Draws a list of triangles with the sprite's texture on it.
void setBytes (const unsigned char *)
- Public Member Functions inherited from Drawable
 Drawable (const Drawable &)=default
Drawableoperator= (const Drawable &)=default
 Drawable (Drawable &&)=default
Drawableoperator= (Drawable &&)=default
virtual void setPos (double x, double y)
template<class Vect >
Vect getCenter () const
virtual void setCenter (double x, double y)
template<class Vect >
void setCenter (Vect c)
double getLeft () const
 Returns the distance from the left side of the screen.
void setLeft (double x)
double getTop () const
 Returns the distance from the top of the screen.
void setTop (double y)
double getRight () const
 Returns the distance from the right side of the screen.
void setRight (double x)
double getBottom () const
 Returns the distance from the bottom of the screen.
void setBottom (double y)
double getX () const
void setX (double)
double getY () const
void setY (double)
Vec2 getSize () const
 Returns {width, height} in screen coordinates.
float getWidth () const
 Returns the width in screen coordinates.
float getHeight () const
 Returns the height in screen coordinates.

Static Public Member Functions

static const ShadervertexShader ()
 Returns a reference to JNGL's default vertex shader used to draw textures.

Public Attributes

std::shared_ptr< Finallyloader
 Function which actually loads the sprite.

Additional Inherited Members

- Protected Attributes inherited from Drawable
double x = 0
double y = 0
float width = 0
float height = 0

Detailed Description

Higher-level representation of an image.

Definition at line 19 of file sprite.hpp.

Inheritance diagram for Sprite:
Collaboration diagram for Sprite:

Member Function Documentation

◆ drawScaled()

void drawScaled ( float  xfactor,
float  yfactor,
const ShaderProgram shaderProgram = nullptr 
) const

Draws the image scaled around its center by xfactor and yfactor

xfactorScale width by this factor
yfactorScale height by this factor
shaderProgramPassing nullptr uses the default.

drawScaled(1, 1) would draw it normally. You can pass negative values to flip the image. For example drawScaled(-1, 1) would draw the image horizontally flipped.

◆ drawClipped()

void drawClipped ( float  xstart,
float  xend,
float  ystart,
float  yend 
) const
Use new drawClipped(Vec2, Vec2) method instead

The documentation for this class was generated from the following file: