phaser/src/gameobjects/shader/ShaderCreator.js

48 lines
1.7 KiB
JavaScript
Raw Normal View History

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.
*
* @method Phaser.GameObjects.GameObjectCreator#shader
* @since 3.17.0
2019-04-25 02:15:51 +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.
*/
GameObjectCreator.register('shader', function (config, addToScene)
2019-04-25 02:15:51 +00:00
{
if (config === undefined) { config = {}; }
var key = GetAdvancedValue(config, 'key', null);
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
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;
}
BuildGameObject(this.scene, shader, config);
2019-04-25 02:15:51 +00:00
return shader;
2019-04-25 02:15:51 +00:00
});
// When registering a factory function 'this' refers to the GameObjectCreator context.