JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
Drawable Class Referenceabstract

Base class for drawable objects with a position and a rectangle size. More...

#include <jngl/Drawable.hpp>

Public Member Functions

 Drawable (const Drawable &)=default
 
Drawableoperator= (const Drawable &)=default
 
 Drawable (Drawable &&)=default
 
Drawableoperator= (Drawable &&)=default
 
virtual void step ()=0
 Advance object's state. More...
 
virtual void draw () const =0
 Called when drawing a frame. More...
 
virtual void setPos (double x, double y)
 Sets the position of the top-left of the Drawable.
 
template<class Vect >
void setPos (Vect p)
 Sets the position of the top-left of the Drawable. More...
 
jngl::Vec2 getCenter () const
 Returns the position of the center of the Drawable.
 
virtual void setCenter (double x, double y)
 Centers the Sprite at (x, y)
 
template<class Vect >
void setCenter (Vect c)
 Centers the Sprite at c (e.g. jngl::Vec2) More...
 
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.
 
void drawBoundingBox () const
 Draws a red box around the Drawable.
 
bool contains (jngl::Vec2 point) const
 Returns whether point is inside the bounding box.
 

Protected Attributes

Vec2 position
 
float width = 0
 
float height = 0
 

Detailed Description

Base class for drawable objects with a position and a rectangle size.

Definition at line 12 of file Drawable.hpp.

Inheritance diagram for Drawable:
[legend]
Collaboration diagram for Drawable:
[legend]

Member Function Documentation

◆ step()

virtual void step ( )
pure virtual

Advance object's state.

Implemented in Sprite, and Text.

◆ draw()

virtual void draw ( ) const
pure virtual

Called when drawing a frame.

Implemented in Sprite, and Text.

◆ setPos()

void setPos ( Vect  p)
inline

Sets the position of the top-left of the Drawable.

Definition at line 31 of file Drawable.hpp.

◆ setCenter()

void setCenter ( Vect  c)
inline

Centers the Sprite at c (e.g. jngl::Vec2)

Definition at line 42 of file Drawable.hpp.

Member Data Documentation

◆ position

Vec2 position
protected

Definition at line 84 of file Drawable.hpp.

◆ width

float width = 0
protected

Definition at line 85 of file Drawable.hpp.

◆ height

float height = 0
protected

Definition at line 86 of file Drawable.hpp.


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