Skip to content

Renderer: add dashed line support #1351

@obiot

Description

@obiot

Summary

Add setLineDash(), getLineDash(), and lineDashOffset to the renderer API, matching the Canvas 2D API.

Requirements

  • setLineDash(segments) — set the dash pattern (array of on/off lengths)
  • getLineDash() — return the current dash pattern
  • lineDashOffset — offset for where the dash pattern starts
  • Available on both Canvas and WebGL renderers

Use Cases

  • Debug drawing (collision shapes, grid lines, bounding boxes)
  • Range/radius indicators in strategy games
  • UI elements (selection borders, focus indicators)
  • Path previews in level editors

Approach

Canvas renderer: Direct pass-through to ctx.setLineDash() / ctx.getLineDash() / ctx.lineDashOffset.

WebGL renderer: Implement in the primitive batcher. When drawing lines, compute cumulative distance along the line segments, then use the dash pattern array to alternate between drawing and skipping segments. Store the dash state alongside the existing lineWidth / lineJoin properties. The batcher emits geometry only for the "on" portions of the dash pattern.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions