fledge_render_2d library

2D rendering components for Fledge.

This library provides 2D-specific rendering components:

  • Transform2D: Local position, rotation, and scale
  • GlobalTransform2D: Computed world-space transform
  • Camera2D: 2D camera with orthographic projection
  • Sprite: Textured quad rendering
  • SpriteBatch: Efficient batched sprite rendering

Transforms

Use Transform2D for local transforms relative to parent:

world.spawn()
  ..insert(Transform2D(
    translation: Vector2(100, 200),
    rotation: math.pi / 4,
    scale: Vector2.all(2),
  ));

The TransformPropagateSystem computes GlobalTransform2D from the entity hierarchy.

Camera

Create a camera with Camera2D:

world.spawn()
  ..insert(Transform2D.from(0, 0))
  ..insert(Camera2D(
    projection: OrthographicProjection(viewportHeight: 20),
  ));

Sprites

Render textured quads with Sprite:

world.spawn()
  ..insert(Sprite(texture: playerTexture))
  ..insert(Transform2D.from(100, 200));

Or use SpriteBundle for convenience:

SpriteBundle(texture: playerTexture, x: 100, y: 200).spawn(world);

dart:ui types

This package uses standard dart:ui types like Color, Rect, Offset, and Size. Import them directly from dart:ui:

import 'dart:ui' show Color, Rect;

Classes

AnimateSystem
System that updates animation players and applies sprite changes.
AnimateSystemWithResource
System that uses AnimationTime resource for delta time.
AnimationClip
A sequence of animation frames.
AnimationFrame
A single frame in an animation.
AnimationPlayer
Plays animation clips on entities.
AnimationTime
Resource to track animation delta time.
AtlasSprite
A sprite that references an atlas and an index.
AtlasSpriteExtractor
Extractor for atlas sprite components.
BackendSpriteData
Sprite data for backend rendering.
Camera2D
2D camera component.
CameraDriverContext
Context for the camera driver node.
CameraDriverNode
Render node that sets up the camera for subsequent nodes.
CameraView
Camera view data passed through render graph slots.
ColorMaterial
Material for rendering colored shapes without texture.
ExtractedSprite
Extracted sprite data for the render world.
FloatUniform
Float uniform value.
GlobalTransform2D
Computed global transform (world space).
GridAtlasLayout
Grid-based texture atlas layout.
Mat4Uniform
Matrix4 uniform value.
Material2D
Base class for 2D materials.
Orientation
Component tracking which direction an entity is facing.
OrthographicProjection
Orthographic projection settings for 2D rendering.
RectAtlasLayout
Rectangle-based texture atlas layout.
ShaderEffects
Pre-built shader effects for common use cases.
ShaderHandle
Reference to a shader program.
ShaderMaterial
Material that uses a custom shader program.
Sprite
Sprite component for textured quad rendering.
SpriteBatch
A batch of sprites sharing the same texture.
SpriteBatches
Collection of sprite batches organized by texture.
SpriteBatchSystem
System that batches extracted sprites for efficient rendering.
SpriteBundle
Convenience bundle for spawning sprite entities.
SpriteExtractor
Extractor for sprite components.
SpriteInstance
A single sprite instance in a batch.
SpriteMaterial
Standard material for sprite rendering.
SpriteRenderContext
Context for sprite rendering.
SpriteRenderNode
Render node that draws sprite batches.
TextureAtlas
A texture atlas (sprite sheet) for efficient sprite rendering.
TextureAtlasLayout
Layout information for a texture atlas.
TextureHandle
Handle to a texture resource.
TextureUniform
Texture uniform value.
Transform2D
2D transform component.
TransformPropagateSystem
System that propagates local transforms through the entity hierarchy to compute global (world-space) transforms.
TransitionFadeSystem
System that updates fade animation progress during transitions.
TransitionState
Resource tracking scene transition state.
UniformValue
Uniform value that can be passed to shaders.
Vec2Uniform
Vec2 uniform value.
Vec3Uniform
Vec3 uniform value.
Vec4Uniform
Vec4 uniform value.
Viewport
Viewport rectangle for camera rendering.
ViewportSize
Resource that stores the current viewport (screen) dimensions.
Visibility
Visibility component to hide entities from rendering.

Enums

AnimationState
State of an animation player.
BlendMode
Blend mode for sprite rendering.
Direction
Cardinal direction for 2D character orientation.
ScalingMode
Scaling mode for orthographic projection.
TransitionPhase
Phases of a scene transition.

Extensions

PixelPerfectVector2 on Vector2
Extension methods for pixel-perfect Vector2 operations.

Functions

propagateTransforms(World world) → void
Convenience function to create and run the transform propagation system.
snapToPixel(double value) double
Utilities for pixel-perfect 2D rendering.
snapVector2ToPixel(Vector2 position) → Vector2
Snap a Vector2 position to the nearest pixel.
snapVector2ToPixelInPlace(Vector2 position) → void
Snap a Vector2 position to pixels, modifying in place.