|
| 1 | +/** |
| 2 | + * @author Richard Davey <rich@photonstorm.com> |
| 3 | + * @copyright 2018 Photon Storm Ltd. |
| 4 | + * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} |
| 5 | + */ |
| 6 | + |
| 7 | +var Class = require('../../utils/Class'); |
| 8 | +var Components = require('../components'); |
| 9 | +var GameObject = require('../GameObject'); |
| 10 | +var DOMElementRender = require('./DOMElementRender'); |
| 11 | + |
| 12 | +/** |
| 13 | + * @classdesc |
| 14 | + * [description] |
| 15 | + * |
| 16 | + * @class DOMElement |
| 17 | + * @extends Phaser.GameObjects.GameObject |
| 18 | + * @memberOf Phaser.GameObjects |
| 19 | + * @constructor |
| 20 | + * @since 3.12.0 |
| 21 | + * |
| 22 | + * @extends Phaser.GameObjects.Components.Alpha |
| 23 | + * @extends Phaser.GameObjects.Components.BlendMode |
| 24 | + * @extends Phaser.GameObjects.Components.Depth |
| 25 | + * @extends Phaser.GameObjects.Components.Flip |
| 26 | + * @extends Phaser.GameObjects.Components.GetBounds |
| 27 | + * @extends Phaser.GameObjects.Components.Mask |
| 28 | + * @extends Phaser.GameObjects.Components.Origin |
| 29 | + * @extends Phaser.GameObjects.Components.Pipeline |
| 30 | + * @extends Phaser.GameObjects.Components.ScaleMode |
| 31 | + * @extends Phaser.GameObjects.Components.ScrollFactor |
| 32 | + * @extends Phaser.GameObjects.Components.Size |
| 33 | + * @extends Phaser.GameObjects.Components.TextureCrop |
| 34 | + * @extends Phaser.GameObjects.Components.Tint |
| 35 | + * @extends Phaser.GameObjects.Components.Transform |
| 36 | + * @extends Phaser.GameObjects.Components.Visible |
| 37 | + * |
| 38 | + * @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. |
| 39 | + * @param {number} x - The horizontal position of this Game Object in the world. |
| 40 | + * @param {number} y - The vertical position of this Game Object in the world. |
| 41 | + * @param {string} texture - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. |
| 42 | + */ |
| 43 | +var DOMElement = new Class({ |
| 44 | + |
| 45 | + Extends: GameObject, |
| 46 | + |
| 47 | + Mixins: [ |
| 48 | + Components.Alpha, |
| 49 | + Components.BlendMode, |
| 50 | + Components.Depth, |
| 51 | + // Components.Flip, |
| 52 | + // Components.GetBounds, |
| 53 | + // Components.Mask, |
| 54 | + // Components.Origin, |
| 55 | + // Components.Pipeline, |
| 56 | + // Components.ScaleMode, |
| 57 | + Components.ScrollFactor, |
| 58 | + // Components.Size, |
| 59 | + // Components.TextureCrop, |
| 60 | + // Components.Tint, |
| 61 | + Components.Transform, |
| 62 | + Components.Visible, |
| 63 | + DOMElementRender |
| 64 | + ], |
| 65 | + |
| 66 | + initialize: |
| 67 | + |
| 68 | + function DOMElement (scene, x, y, element) |
| 69 | + { |
| 70 | + GameObject.call(this, scene, 'DOMElement'); |
| 71 | + |
| 72 | + // this.setTexture(texture, frame); |
| 73 | + this.setPosition(x, y); |
| 74 | + // this.setSizeToFrame(); |
| 75 | + // this.setOriginFromFrame(); |
| 76 | + // this.initPipeline('TextureTintPipeline'); |
| 77 | + |
| 78 | + this.parent = scene.sys.game.domContainer; |
| 79 | + |
| 80 | + this.node; |
| 81 | + |
| 82 | + this.setNode(element); |
| 83 | + }, |
| 84 | + |
| 85 | + setNode: function (element) |
| 86 | + { |
| 87 | + var target; |
| 88 | + |
| 89 | + if (typeof element === 'string') |
| 90 | + { |
| 91 | + target = document.getElementById(element); |
| 92 | + } |
| 93 | + else if (typeof element === 'object' && element.nodeType === 1) |
| 94 | + { |
| 95 | + target = element; |
| 96 | + } |
| 97 | + |
| 98 | + if (!target) |
| 99 | + { |
| 100 | + return; |
| 101 | + } |
| 102 | + |
| 103 | + this.node = target; |
| 104 | + |
| 105 | + target.style.zIndex = '0'; |
| 106 | + target.style.position = 'absolute'; |
| 107 | + |
| 108 | + if (this.parent) |
| 109 | + { |
| 110 | + this.parent.appendChild(target); |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | +}); |
| 115 | + |
| 116 | +module.exports = DOMElement; |
0 commit comments