Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
esengine::ecs::Canvas Struct Reference

Canvas component for 2D game resolution management. More...

#include <Canvas.hpp>

Public Member Functions

 Canvas ()=default

Public Attributes

glm::uvec2 designResolution {1920, 1080}
 Design resolution in pixels.
f32 pixelsPerUnit {100.0f}
 World pixels per physics meter (e.g., 100 means 100px = 1 Box2D meter).
CanvasScaleMode scaleMode {CanvasScaleMode::FixedHeight}
 Scaling mode for different screen resolutions.
f32 matchWidthOrHeight {0.5f}
 Match factor for Match scale mode (0 = width, 1 = height).
glm::vec4 backgroundColor {0.0f, 0.0f, 0.0f, 1.0f}
 Background color for letterbox/pillarbox areas.
i32 layer {0}
 Sorting layer this canvas' UI belongs to, for Camera.cullingMask. Membership only — UI draw order comes from the tree, not from this.

Detailed Description

Canvas component for 2D game resolution management.

Defines the design resolution and scaling behavior for 2D games. The Canvas works with the Camera component to ensure consistent rendering across different screen resolutions.

Entity canvas = registry.create();
auto& c = registry.emplace<Canvas>(canvas);
c.designResolution = {1920, 1080};
c.pixelsPerUnit = 100.0f; // 100 pixels = 1 world unit
Entity identifier with packed index + generation.
Definition Types.hpp:135

Workflow:

  1. Artist creates assets at design resolution (e.g., 1920x1080)
  2. World units are design pixels: a 100x200 texture spawns a 100x200 sprite, and the default scene camera shows designResolution.y world units of height (orthoSize = designResolution.y / 2)
  3. pixelsPerUnit is the physics scale: world pixels per Box2D meter
  4. At runtime, scaleMode fits the design resolution to the actual screen

Definition at line 71 of file Canvas.hpp.

Constructor & Destructor Documentation

◆ Canvas()

esengine::ecs::Canvas::Canvas ( )
default

Member Data Documentation

◆ backgroundColor

glm::vec4 esengine::ecs::Canvas::backgroundColor {0.0f, 0.0f, 0.0f, 1.0f}

Background color for letterbox/pillarbox areas.

Definition at line 90 of file Canvas.hpp.

Referenced by canvasApplyJS(), and canvasToJS().

◆ designResolution

glm::uvec2 esengine::ecs::Canvas::designResolution {1920, 1080}

Design resolution in pixels.

Definition at line 74 of file Canvas.hpp.

Referenced by canvasApplyJS(), and canvasToJS().

◆ layer

i32 esengine::ecs::Canvas::layer {0}

Sorting layer this canvas' UI belongs to, for Camera.cullingMask. Membership only — UI draw order comes from the tree, not from this.

Definition at line 95 of file Canvas.hpp.

Referenced by canvasApplyJS(), and canvasToJS().

◆ matchWidthOrHeight

f32 esengine::ecs::Canvas::matchWidthOrHeight {0.5f}

Match factor for Match scale mode (0 = width, 1 = height).

Definition at line 86 of file Canvas.hpp.

Referenced by canvasApplyJS(), and canvasToJS().

◆ pixelsPerUnit

f32 esengine::ecs::Canvas::pixelsPerUnit {100.0f}

World pixels per physics meter (e.g., 100 means 100px = 1 Box2D meter).

Definition at line 78 of file Canvas.hpp.

Referenced by canvasApplyJS(), and canvasToJS().

◆ scaleMode

CanvasScaleMode esengine::ecs::Canvas::scaleMode {CanvasScaleMode::FixedHeight}

Scaling mode for different screen resolutions.

Definition at line 82 of file Canvas.hpp.

Referenced by canvasApplyJS(), and canvasToJS().


The documentation for this struct was generated from the following file:
  • /home/runner/work/estella/estella/src/esengine/ecs/components/Canvas.hpp