ge211  2021.5.1
A student game engine
Render_sprite Class Reference

Detailed Description

A Render_sprite works by allowing its derived classes to render themselves pixel-by-pixel onto an SDL_Surface.

Then it converts the rendered surface into a Texture, which it caches.

The constructor of the derived class should pass the required dimensions to the Render_sprite constructor. Then, in its own constructor, use fill_surface(), fill_rectangle(), and set_pixel() to paint the desired sprite image to the surface. Or for direct access to the underlying SDL_Surface, use raw_surface().

Definition at line 104 of file ge211_sprites.hxx.

+ Inheritance diagram for Render_sprite:
+ Collaboration diagram for Render_sprite:

Protected Member Functions

 Render_sprite (Dims< int >)
 Constructs a Render_sprite with the given pixel dimensions. More...
 
bool can_paint () const
 Returns whether we can paint to this Render_sprite. More...
 
void fill_surface (Color)
 Fills the whole surface with the given color. More...
 
void fill_rectangle (Rect< int >, Color)
 Fills the given rectangle in the given color. More...
 
void set_pixel (Posn< int >, Color)
 Sets one pixel to the given color. More...
 
Borrowed< SDL_Surface > raw_surface ()
 Gains access to the underlying SDL_Surface. More...
 

Constructor & Destructor Documentation

◆ Render_sprite()

Render_sprite ( Dims< int >  dimensions)
explicitprotected

Constructs a Render_sprite with the given pixel dimensions.

Preconditions

  • Both dimensions are positive.

Definition at line 66 of file ge211_sprites.cxx.

Member Function Documentation

◆ can_paint()

bool can_paint ( ) const
protected

Returns whether we can paint to this Render_sprite.

If this sprite has already been rendered to the screen then this function returns false. When the result is false, then calling any of fill_surface(), fill_rectangle(), set_pixel(), or raw_surface() will throw an exceptions::Late_paint_error exception.

◆ fill_rectangle()

void fill_rectangle ( Rect< int >  rect,
Color  color 
)
protected

Fills the given rectangle in the given color.

Typically this will only be called from a derived class's constructor.

Precondition

Throws exceptions::Late_paint_error if !can_paint().

Definition at line 81 of file ge211_sprites.cxx.

◆ fill_surface()

void fill_surface ( Color  color)
protected

Fills the whole surface with the given color.

Typically this will only be called from a derived class's constructor.

Precondition

Throws exceptions::Late_paint_error if !can_paint().

Definition at line 75 of file ge211_sprites.cxx.

◆ raw_surface()

Borrowed< SDL_Surface > raw_surface ( )
protected

Gains access to the underlying SDL_Surface.

Typically this will only be called from a derived class's constructor. Never returns null.

Precondition

Throws exceptions::Late_paint_error if !can_paint().

Definition at line 70 of file ge211_sprites.cxx.

◆ set_pixel()

void set_pixel ( Posn< int >  xy,
Color  color 
)
protected

Sets one pixel to the given color.

Typically this will only be called from a derived class's constructor.

Precondition

Throws exceptions::Late_paint_error if !can_paint().

Definition at line 86 of file ge211_sprites.cxx.


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