* Create a 2D point light. * * A `Light2d` is a first-class world Renderable: add it to a container * with `app.world.addChild(light)` (or any sub-container, including a * `Sprite`, so the light follows the parent via its transform). On * activation, the light auto-registers with the activ
( x: number, y: number, radiusX: number, radiusY: number = radiusX, color: Color | string = "#FFF", intensity: number = 0.7, )
| 111 | * @param [intensity=0.7] - The peak alpha of the radial gradient at the light's center (0–1). |
| 112 | */ |
| 113 | constructor( |
| 114 | x: number, |
| 115 | y: number, |
| 116 | radiusX: number, |
| 117 | radiusY: number = radiusX, |
| 118 | color: Color | string = "#FFF", |
| 119 | intensity: number = 0.7, |
| 120 | ) { |
| 121 | // pos is the light's CENTER (matches `Ellipse(x, y, w, h)` and |
| 122 | // `Sprite` conventions); the centered anchor below makes Renderable's |
| 123 | // transform stack scale/rotate around that center too. |
| 124 | super(x, y, radiusX * 2, radiusY * 2); |
| 125 | |
| 126 | this.color = colorPool.get(); |
| 127 | if (color instanceof Color) { |
| 128 | this.color.copy(color); |
| 129 | } else { |
| 130 | this.color.parseCSS(color); |
| 131 | } |
| 132 | |
| 133 | this.radiusX = radiusX; |
| 134 | this.radiusY = radiusY; |
| 135 | this.intensity = intensity; |
| 136 | |
| 137 | /** |
| 138 | * the default blend mode to be applied when rendering this light |
| 139 | * @see CanvasRenderer#setBlendMode |
| 140 | * @see WebGLRenderer#setBlendMode |
| 141 | */ |
| 142 | this.blendMode = "lighter"; |
| 143 | |
| 144 | // initial shape — `getVisibleArea()` rewrites this each frame from |
| 145 | // transform-aware bounds. |
| 146 | this.visibleArea = ellipsePool.get( |
| 147 | this.pos.x, |
| 148 | this.pos.y, |
| 149 | this.width, |
| 150 | this.height, |
| 151 | ); |
| 152 | |
| 153 | // centered anchor — transforms (scale, rotate) pivot around `pos`. |
| 154 | this.anchorPoint.set(0.5, 0.5); |
| 155 | |
| 156 | this.illuminationOnly = false; |
| 157 | this.lightHeight = Math.max(radiusX, radiusY) * 0.075; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * the horizontal coordinate of this light's center. |