mirror of
https://github.com/photonstorm/phaser
synced 2024-12-23 19:43:28 +00:00
47 lines
1.7 KiB
JavaScript
47 lines
1.7 KiB
JavaScript
/**
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
* @copyright 2013-2023 Photon Storm Ltd.
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
|
*/
|
|
|
|
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
|
|
*
|
|
* @param {Phaser.Types.GameObjects.Shader.ShaderConfig} config - The configuration object this Game Object will use to create itself.
|
|
* @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)
|
|
{
|
|
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);
|
|
|
|
var shader = new Shader(this.scene, key, x, y, width, height);
|
|
|
|
if (addToScene !== undefined)
|
|
{
|
|
config.add = addToScene;
|
|
}
|
|
|
|
BuildGameObject(this.scene, shader, config);
|
|
|
|
return shader;
|
|
});
|
|
|
|
// When registering a factory function 'this' refers to the GameObjectCreator context.
|