Engine
Raylib based game framework
Loading...
Searching...
No Matches
Renderer Class Reference

Draws all entities with Sprite and Transform components. More...

#include <Renderer.hpp>

Public Member Functions

void Init (Registry &registry, const float virtualWidth, const float virtualHeight)
 Initialises the renderer and registers sprite change callbacks.

Static Public Member Functions

static bool SetSprite (const Entity entity, const Component::Sprite &sprite)
 Assigns or replaces the Sprite component on an entity.
static void RemoveSprite (const Entity entity)
 Removes the Sprite component from an entity.

Public Attributes

Camera2D camera

Friends

class Engine

Detailed Description

Draws all entities with Sprite and Transform components.

Manages a sorted sprite pool and a 2D camera. Sprites are sorted by layer then by texture ID so draw calls are batched as much as possible. Entities missing a valid texture are rendered with a purple/black checkerboard placeholder until one is assigned.

The camera is public so scenes can manipulate it directly.

Member Function Documentation

◆ Init()

void Renderer::Init ( Registry & registry,
const float virtualWidth,
const float virtualHeight )

Initialises the renderer and registers sprite change callbacks.

Called automatically by the Engine constructor. Registers OnConstruct, OnUpdate, and OnDestroy callbacks on Component::Sprite so the sprite pool is re-sorted whenever the set of sprites changes.

Parameters
registryRegistry to watch for sprite changes
virtualWidthWidth of the virtual canvas in pixels
virtualHeightHeight of the virtual canvas in pixels

◆ RemoveSprite()

void Renderer::RemoveSprite ( const Entity entity)
static

Removes the Sprite component from an entity.

Does nothing if the entity does not have a sprite.

Parameters
entityTarget entity

◆ SetSprite()

bool Renderer::SetSprite ( const Entity entity,
const Component::Sprite & sprite )
static

Assigns or replaces the Sprite component on an entity.

Returns false and leaves the entity unchanged if the sprite's texture is invalid.

Parameters
entityTarget entity
spriteSprite to assign
Returns
True if the sprite was applied successfully

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