Skip to content

ColorLayer silently ignores pos/scale/parent transform #1436

@obiot

Description

@obiot

Problem

ColorLayer is constructed as super(0, 0, Infinity, Infinity) with the default 0.5 anchor. By the time ColorLayer.draw() runs, Renderable.preDraw has already translated by (-anchorX·width, -anchorY·height) = (-Infinity, -Infinity), leaving currentTransform.tx/ty non-finite.

Effects:

  • Any user-set colorLayer.pos.set(...) is masked by the -Infinity translate.
  • Nesting a ColorLayer inside a transformed Container (translate/scale/rotate) has no effect — the parent transform composes with -Infinity and stays non-finite.
  • ColorLayer.draw() calls renderer.clipRect(0, 0, viewport.w, viewport.h). On WebGL this only "works" because of the non-finite-transform guard added in fix(clipping): correct Container.clipping under nested transforms (closes #1349) #1435 — it falls through to "no scissor", then clearColor paints the full framebuffer.

So ColorLayer is effectively a "fill the entire framebuffer with this color" command, not a positionable layer. The class API (pos, parent containers, etc.) suggests otherwise.

This came up while reviewing PR #1435 — a custom PartialColorLayer extends ColorLayer (used in the new clipping example) needed an explicit renderer.resetTransform() to make a sub-rect clipRect work, because the inherited -Infinity translate would otherwise turn the partial-band clip into a no-op.

Proposed fix

Honor pos/size. Drop super(0, 0, Infinity, Infinity) + 0.5 anchor in the constructor. New signature:

ColorLayer(name, color, z?, x?, y?, w?, h?)
  • Defaults to viewport-sized (so the most common "full-canvas backdrop" case stays a one-liner).
  • Anchor stays at (0, 0) so pos means top-left.
  • draw() issues clipRect(0, 0, this.width, this.height) under the layer's own (finite) transform — sub-rect bands, transformed parents, and pos changes all just work.
  • The clipping example's PartialColorLayer workaround can then be deleted.

Out of scope for #1435 (which is the clipRect fix). Happy to take this in a follow-up PR.

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