Skip to content

Commit c1bf08d

Browse files
committed
New Point Light class
1 parent ea6a7d0 commit c1bf08d

1 file changed

Lines changed: 34 additions & 79 deletions

File tree

src/gameobjects/lights/PointLight.js

Lines changed: 34 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@
77
var Class = require('../../utils/Class');
88
var Components = require('../components');
99
var GameObject = require('../GameObject');
10+
var GetCalcMatrix = require('../GetCalcMatrix');
1011
var IntegerToRGB = require('../../display/color/IntegerToRGB');
1112
var RGB = require('../../display/RGB');
1213

1314
/**
1415
* @classdesc
15-
* An Image Game Object.
1616
*
17-
* An Image is a light-weight Game Object useful for the display of static images in your game,
18-
* such as logos, backgrounds, scenery or other non-animated elements. Images can have input
19-
* events and physics bodies, or be tweened, tinted or scrolled. The main difference between an
20-
* Image and a Sprite is that you cannot animate an Image as they do not have the Animation component.
17+
* TODO
2118
*
2219
* @class PointLight
2320
* @extends Phaser.GameObjects.GameObject
@@ -57,15 +54,16 @@ var PointLight = new Class({
5754

5855
initialize:
5956

60-
function PointLight (scene, x, y, color, radius, intensity)
57+
function PointLight (scene, x, y, color, radius, intensity, falloff)
6158
{
6259
if (color === undefined) { color = 0xffffff; }
6360
if (radius === undefined) { radius = 128; }
64-
if (intensity === undefined) { intensity = 10; }
61+
if (intensity === undefined) { intensity = 1; }
62+
if (falloff === undefined) { falloff = radius * 2; }
6563

6664
GameObject.call(this, scene, 'PointLight');
6765

68-
this.initPipeline('Light2D');
66+
this.initPipeline('PointLightPipeline');
6967

7068
this.setPosition(x, y);
7169

@@ -78,40 +76,48 @@ var PointLight = new Class({
7876
);
7977

8078
this.intensity = intensity;
79+
this.attenuation = 0.1;
8180

8281
// read only:
83-
this.width = radius * 2;
84-
this.height = radius * 2;
82+
this.width = falloff * 2;
83+
this.height = falloff * 2;
8584

8685
// private
87-
this._radius = radius;
86+
this.radius = radius;
87+
this._falloff = falloff;
8888
},
8989

90-
radius: {
90+
// radius: {
91+
92+
// get: function ()
93+
// {
94+
// return this._radius;
95+
// },
96+
97+
// set: function (value)
98+
// {
99+
// this._radius = value;
100+
// }
101+
102+
// },
103+
104+
falloff: {
91105

92106
get: function ()
93107
{
94-
return this._radius;
108+
return this._falloff;
95109
},
96110

97111
set: function (value)
98112
{
99-
this._radius = value;
113+
this._falloff = value;
114+
100115
this.width = value * 2;
101116
this.height = value * 2;
102117
}
103118

104119
},
105120

106-
/**
107-
* Internal value to allow Containers to be used for input and physics.
108-
* Do not change this value. It has no effect other than to break things.
109-
*
110-
* @name Phaser.GameObjects.Container#originX
111-
* @type {number}
112-
* @readonly
113-
* @since 3.4.0
114-
*/
115121
originX: {
116122

117123
get: function ()
@@ -121,15 +127,6 @@ var PointLight = new Class({
121127

122128
},
123129

124-
/**
125-
* Internal value to allow Containers to be used for input and physics.
126-
* Do not change this value. It has no effect other than to break things.
127-
*
128-
* @name Phaser.GameObjects.Container#originY
129-
* @type {number}
130-
* @readonly
131-
* @since 3.4.0
132-
*/
133130
originY: {
134131

135132
get: function ()
@@ -139,15 +136,6 @@ var PointLight = new Class({
139136

140137
},
141138

142-
/**
143-
* Internal value to allow Containers to be used for input and physics.
144-
* Do not change this value. It has no effect other than to break things.
145-
*
146-
* @name Phaser.GameObjects.Container#displayOriginX
147-
* @type {number}
148-
* @readonly
149-
* @since 3.4.0
150-
*/
151139
displayOriginX: {
152140

153141
get: function ()
@@ -157,15 +145,6 @@ var PointLight = new Class({
157145

158146
},
159147

160-
/**
161-
* Internal value to allow Containers to be used for input and physics.
162-
* Do not change this value. It has no effect other than to break things.
163-
*
164-
* @name Phaser.GameObjects.Container#displayOriginY
165-
* @type {number}
166-
* @readonly
167-
* @since 3.4.0
168-
*/
169148
displayOriginY: {
170149

171150
get: function ()
@@ -175,45 +154,21 @@ var PointLight = new Class({
175154

176155
},
177156

178-
renderWebGL: function (renderer, src, camera, parentTransformMatrix)
157+
renderWebGL: function (renderer, src, camera, parentMatrix)
179158
{
180159
var pipeline = renderer.pipelines.set(src.pipeline);
181160

182-
var camMatrix = pipeline.tempMatrix1;
183-
var lightMatrix = pipeline.tempMatrix2;
184-
var calcMatrix = pipeline.tempMatrix3;
161+
var calcMatrix = GetCalcMatrix(src, camera, parentMatrix).calc;
185162

186163
var width = src.width;
187164
var height = src.height;
188165

189-
var x = -src.radius;
190-
var y = -src.radius;
166+
var x = -src._falloff;
167+
var y = -src._falloff;
191168

192169
var xw = x + width;
193170
var yh = y + height;
194171

195-
lightMatrix.applyITRS(src.x, src.y, src.rotation, src.scaleX, src.scaleY);
196-
197-
camMatrix.copyFrom(camera.matrix);
198-
199-
if (parentTransformMatrix)
200-
{
201-
// Multiply the camera by the parent matrix
202-
camMatrix.multiplyWithOffset(parentTransformMatrix, -camera.scrollX * src.scrollFactorX, -camera.scrollY * src.scrollFactorY);
203-
204-
// Undo the camera scroll
205-
lightMatrix.e = src.x;
206-
lightMatrix.f = src.y;
207-
}
208-
else
209-
{
210-
lightMatrix.e -= camera.scrollX * src.scrollFactorX;
211-
lightMatrix.f -= camera.scrollY * src.scrollFactorY;
212-
}
213-
214-
// Multiply by the Sprite matrix, store result in calcMatrix
215-
camMatrix.multiply(lightMatrix, calcMatrix);
216-
217172
var lightX = calcMatrix.getX(0, 0);
218173
var lightY = calcMatrix.getY(0, 0);
219174

@@ -229,7 +184,7 @@ var PointLight = new Class({
229184
var tx3 = calcMatrix.getX(xw, y);
230185
var ty3 = calcMatrix.getY(xw, y);
231186

232-
pipeline.batchLight(src, camera, tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, lightX, lightY);
187+
pipeline.batchPointLight(src, camera, tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, lightX, lightY);
233188
}
234189

235190
});

0 commit comments

Comments
 (0)