phaser/src/gameobjects/shader/ShaderFactory.js

35 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-04-25 02:15:51 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Shader = require('./Shader');
var GameObjectFactory = require('../GameObjectFactory');
/**
* Creates a new Shader Game Object and adds it to the Scene.
*
* Note: This method will only be available if the Shader Game Object and WebGL support have been built into Phaser.
*
2019-04-25 14:07:46 +00:00
* @method Phaser.GameObjects.GameObjectFactory#shader
2019-04-25 02:15:51 +00:00
* @webglOnly
2019-04-25 14:07:46 +00:00
* @since 3.17.0
2019-04-25 02:15:51 +00:00
*
* @param {(string|Phaser.Display.BaseShader)} key - The key of the shader to use from the shader cache, or a BaseShader instance.
2019-04-25 14:07:46 +00:00
* @param {number} [x=0] - The horizontal position of this Game Object in the world.
* @param {number} [y=0] - The vertical position of this Game Object in the world.
* @param {number} [width=128] - The width of the Game Object.
* @param {number} [height=128] - The height of the Game Object.
* @param {string[]} [textures] - Optional array of texture keys to bind to the iChannel0...3 uniforms. The textures must already exist in the Texture Manager.
2019-04-25 02:15:51 +00:00
*
* @return {Phaser.GameObjects.Shader} The Game Object that was created.
*/
if (typeof WEBGL_RENDERER)
{
2019-04-30 23:05:22 +00:00
GameObjectFactory.register('shader', function (key, x, y, width, height, textures)
2019-04-25 02:15:51 +00:00
{
2019-04-30 23:05:22 +00:00
return this.displayList.add(new Shader(this.scene, key, x, y, width, height, textures));
2019-04-25 02:15:51 +00:00
});
}