2019-04-25 02:15:51 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2023-01-02 17:36:27 +00:00
|
|
|
* @copyright 2013-2023 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2019-04-25 02:15:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
var BuildGameObject = require('../BuildGameObject');
|
|
|
|
var GameObjectCreator = require('../GameObjectCreator');
|
|
|
|
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
|
|
|
|
var Shader = require('./Shader');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new Shader Game Object and returns it.
|
|
|
|
*
|
|
|
|
* Note: This method will only be available if the Shader Game Object and WebGL support have been built into Phaser.
|
|
|
|
*
|
2019-04-30 18:43:50 +00:00
|
|
|
* @method Phaser.GameObjects.GameObjectCreator#shader
|
|
|
|
* @since 3.17.0
|
2019-04-25 02:15:51 +00:00
|
|
|
*
|
2020-10-03 08:40:24 +00:00
|
|
|
* @param {Phaser.Types.GameObjects.Shader.ShaderConfig} config - The configuration object this Game Object will use to create itself.
|
2019-04-25 02:15:51 +00:00
|
|
|
* @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Shader} The Game Object that was created.
|
|
|
|
*/
|
2019-04-30 18:43:50 +00:00
|
|
|
GameObjectCreator.register('shader', function (config, addToScene)
|
2019-04-25 02:15:51 +00:00
|
|
|
{
|
|
|
|
if (config === undefined) { config = {}; }
|
|
|
|
|
|
|
|
var key = GetAdvancedValue(config, 'key', null);
|
2019-04-30 18:43:50 +00:00
|
|
|
var x = GetAdvancedValue(config, 'x', 0);
|
|
|
|
var y = GetAdvancedValue(config, 'y', 0);
|
|
|
|
var width = GetAdvancedValue(config, 'width', 128);
|
|
|
|
var height = GetAdvancedValue(config, 'height', 128);
|
2019-04-25 02:15:51 +00:00
|
|
|
|
2019-04-30 18:43:50 +00:00
|
|
|
var shader = new Shader(this.scene, key, x, y, width, height);
|
2019-04-25 02:15:51 +00:00
|
|
|
|
|
|
|
if (addToScene !== undefined)
|
|
|
|
{
|
|
|
|
config.add = addToScene;
|
|
|
|
}
|
|
|
|
|
2019-04-30 18:43:50 +00:00
|
|
|
BuildGameObject(this.scene, shader, config);
|
2019-04-25 02:15:51 +00:00
|
|
|
|
2019-04-30 18:43:50 +00:00
|
|
|
return shader;
|
2019-04-25 02:15:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// When registering a factory function 'this' refers to the GameObjectCreator context.
|