phaser/src/gameobjects/pointlight/PointLight.js

144 lines
3.2 KiB
JavaScript
Raw Normal View History

2020-10-13 17:17:30 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Class = require('../../utils/Class');
var Components = require('../components');
var GameObject = require('../GameObject');
var IntegerToRGB = require('../../display/color/IntegerToRGB');
var PIPELINES_CONST = require('../../renderer/webgl/pipelines/const');
var Render = require('./PointLightRender');
2020-10-13 17:17:30 +00:00
var RGB = require('../../display/RGB');
/**
* @classdesc
*
2020-12-01 17:23:42 +00:00
* TODO
2020-10-13 17:17:30 +00:00
*
* @class PointLight
* @extends Phaser.GameObjects.GameObject
* @memberof Phaser.GameObjects
* @constructor
* @since 3.50.0
*
* @extends Phaser.GameObjects.Components.AlphaSingle
* @extends Phaser.GameObjects.Components.BlendMode
* @extends Phaser.GameObjects.Components.Depth
* @extends Phaser.GameObjects.Components.GetBounds
* @extends Phaser.GameObjects.Components.Mask
* @extends Phaser.GameObjects.Components.Pipeline
* @extends Phaser.GameObjects.Components.ScrollFactor
* @extends Phaser.GameObjects.Components.Transform
* @extends Phaser.GameObjects.Components.Visible
*
* @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time.
* @param {number} x - The horizontal position of this Game Object in the world.
* @param {number} y - The vertical position of this Game Object in the world.
*/
var PointLight = new Class({
Extends: GameObject,
Mixins: [
Components.AlphaSingle,
Components.BlendMode,
Components.Depth,
Components.GetBounds,
Components.Mask,
Components.Pipeline,
Components.ScrollFactor,
Components.Transform,
Components.Visible,
Render
2020-10-13 17:17:30 +00:00
],
initialize:
function PointLight (scene, x, y, color, radius, intensity)
2020-10-13 17:17:30 +00:00
{
if (color === undefined) { color = 0xffffff; }
if (radius === undefined) { radius = 128; }
2020-12-01 17:23:42 +00:00
if (intensity === undefined) { intensity = 1; }
2020-10-13 17:17:30 +00:00
GameObject.call(this, scene, 'PointLight');
this.initPipeline(PIPELINES_CONST.POINTLIGHT_PIPELINE);
2020-10-13 17:17:30 +00:00
this.setPosition(x, y);
var rgb = IntegerToRGB(color);
this.color = new RGB(
rgb.r / 255,
rgb.g / 255,
rgb.b / 255
);
this.intensity = intensity;
2020-12-01 17:23:42 +00:00
this.attenuation = 0.1;
2020-10-13 17:17:30 +00:00
// read only:
this.width = radius * 2;
this.height = radius * 2;
2020-10-13 17:17:30 +00:00
this._radius = radius;
2020-10-13 17:17:30 +00:00
},
radius: {
2020-10-13 17:17:30 +00:00
get: function ()
{
return this._radius;
2020-10-13 17:17:30 +00:00
},
set: function (value)
{
this._radius = value;
2020-10-13 17:17:30 +00:00
this.width = value * 2;
this.height = value * 2;
}
},
originX: {
get: function ()
{
return 0.5;
}
},
originY: {
get: function ()
{
return 0.5;
}
},
displayOriginX: {
get: function ()
{
return this._radius;
}
},
displayOriginY: {
get: function ()
{
return this._radius;
}
}
});
module.exports = PointLight;