2018-10-29 23:07:30 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2020-01-15 12:07:09 +00:00
|
|
|
* @copyright 2020 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-10-29 23:07:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
var Components = require('../components');
|
|
|
|
var GameObject = require('../GameObject');
|
|
|
|
var ExternRender = require('./ExternRender');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @classdesc
|
2019-01-30 00:02:11 +00:00
|
|
|
* An Extern Game Object is a special type of Game Object that allows you to pass
|
|
|
|
* rendering off to a 3rd party.
|
2020-08-24 18:24:02 +00:00
|
|
|
*
|
2019-01-30 00:02:11 +00:00
|
|
|
* When you create an Extern and place it in the display list of a Scene, the renderer will
|
|
|
|
* process the list as usual. When it finds an Extern it will flush the current batch,
|
2019-02-05 00:03:34 +00:00
|
|
|
* clear down the pipeline and prepare a transform matrix which your render function can
|
|
|
|
* take advantage of, if required.
|
2020-08-24 18:24:02 +00:00
|
|
|
*
|
2021-04-19 07:52:25 +00:00
|
|
|
* The WebGL context is then left in a 'clean' state, ready for you to bind your own shaders,
|
|
|
|
* or draw to it, whatever you wish to do. This should all take place in the `render` method.
|
|
|
|
* The correct way to deploy an Extern object is to create a class that extends it, then
|
|
|
|
* override the `render` (and optionally `preUpdate`) methods and pass off control to your
|
|
|
|
* 3rd party libraries or custom WebGL code there.
|
|
|
|
*
|
|
|
|
* Once you've finished, you should free-up any of your resources.
|
|
|
|
* The Extern will then rebind the Phaser pipeline and carry on rendering the display list.
|
2020-08-24 18:24:02 +00:00
|
|
|
*
|
2019-01-30 00:02:11 +00:00
|
|
|
* Although this object has lots of properties such as Alpha, Blend Mode and Tint, none of
|
|
|
|
* them are used during rendering unless you take advantage of them in your own render code.
|
2018-10-29 23:07:30 +00:00
|
|
|
*
|
|
|
|
* @class Extern
|
|
|
|
* @extends Phaser.GameObjects.GameObject
|
|
|
|
* @memberof Phaser.GameObjects
|
|
|
|
* @constructor
|
|
|
|
* @since 3.16.0
|
|
|
|
*
|
|
|
|
* @extends Phaser.GameObjects.Components.Alpha
|
|
|
|
* @extends Phaser.GameObjects.Components.BlendMode
|
|
|
|
* @extends Phaser.GameObjects.Components.Depth
|
|
|
|
* @extends Phaser.GameObjects.Components.Flip
|
|
|
|
* @extends Phaser.GameObjects.Components.Origin
|
|
|
|
* @extends Phaser.GameObjects.Components.ScrollFactor
|
|
|
|
* @extends Phaser.GameObjects.Components.Size
|
|
|
|
* @extends Phaser.GameObjects.Components.Texture
|
|
|
|
* @extends Phaser.GameObjects.Components.Tint
|
|
|
|
* @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.
|
|
|
|
*/
|
|
|
|
var Extern = new Class({
|
|
|
|
|
|
|
|
Extends: GameObject,
|
|
|
|
|
|
|
|
Mixins: [
|
|
|
|
Components.Alpha,
|
|
|
|
Components.BlendMode,
|
|
|
|
Components.Depth,
|
|
|
|
Components.Flip,
|
|
|
|
Components.Origin,
|
|
|
|
Components.ScrollFactor,
|
|
|
|
Components.Size,
|
|
|
|
Components.Texture,
|
|
|
|
Components.Tint,
|
|
|
|
Components.Transform,
|
|
|
|
Components.Visible,
|
|
|
|
ExternRender
|
|
|
|
],
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function Extern (scene)
|
|
|
|
{
|
|
|
|
GameObject.call(this, scene, 'Extern');
|
2020-08-24 18:24:02 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Overrides Game Object method
|
|
|
|
addedToScene: function ()
|
|
|
|
{
|
|
|
|
this.scene.sys.updateList.add(this);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Overrides Game Object method
|
|
|
|
removedFromScene: function ()
|
|
|
|
{
|
|
|
|
this.scene.sys.updateList.remove(this);
|
2018-10-29 23:07:30 +00:00
|
|
|
},
|
|
|
|
|
2018-11-20 11:02:19 +00:00
|
|
|
preUpdate: function ()
|
2018-10-29 23:07:30 +00:00
|
|
|
{
|
|
|
|
// override this!
|
2018-11-20 11:02:19 +00:00
|
|
|
// Arguments: time, delta
|
2018-10-29 23:07:30 +00:00
|
|
|
},
|
|
|
|
|
2018-11-20 11:02:19 +00:00
|
|
|
render: function ()
|
2018-10-29 23:07:30 +00:00
|
|
|
{
|
|
|
|
// override this!
|
2018-11-20 11:02:19 +00:00
|
|
|
// Arguments: renderer, camera, calcMatrix
|
2018-10-29 23:07:30 +00:00
|
|
|
}
|
2019-01-30 00:02:11 +00:00
|
|
|
|
2018-10-29 23:07:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Extern;
|