Skip to content

Commit d823b7b

Browse files
committed
More flexible Factory function including element, style and innerText setters
1 parent 1b135b2 commit d823b7b

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

src/gameobjects/domelement/DOMElementFactory.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,24 @@ var DOMElement = require('./DOMElement');
88
var GameObjectFactory = require('../GameObjectFactory');
99

1010
/**
11-
* Creates a new Image Game Object and adds it to the Scene.
11+
* Creates a new DOM Element Game Object and adds it to the parent DOM Container.
12+
*
13+
* The game must have been configured with the `dom.createContainer` property set to `true` for this to work.
1214
*
13-
* Note: This method will only be available if the Image Game Object has been built into Phaser.
15+
* Note: This method will only be available if the DOM Element Game Object has been built into Phaser.
1416
*
1517
* @method Phaser.GameObjects.GameObjectFactory#dom
16-
* @since 3.12.0
18+
* @since 3.17.0
1719
*
18-
* @param {number} x - The horizontal position of this Game Object in the world.
19-
* @param {number} y - The vertical position of this Game Object in the world.
20-
* @param {string} element - The DOM element.
20+
* @param {number} x - The horizontal position of this DOM Element in the world.
21+
* @param {number} y - The vertical position of this DOM Element in the world.
22+
* @param {(HTMLElement|string)} [element] - An existing DOM element, or a string. If a string starting with a # it will do a `getElementById` look-up on the string (minus the hash). Without a hash, it represents the type of element to create, i.e. 'div'.
23+
* @param {(string|any)} [style] - If a string, will be set directly as the elements `style` property value. If a plain object, will be iterated and the values transferred. In both cases the values replacing whatever CSS styles may have been previously set.
24+
* @param {string} [innerText] - If given, will be set directly as the elements `innerText` property value, replacing whatever was there before.
2125
*
2226
* @return {Phaser.GameObjects.DOMElement} The Game Object that was created.
2327
*/
24-
GameObjectFactory.register('dom', function (x, y, element)
28+
GameObjectFactory.register('dom', function (x, y, element, style, innerText)
2529
{
26-
return this.displayList.add(new DOMElement(this.scene, x, y, element));
30+
return this.displayList.add(new DOMElement(this.scene, x, y, element, style, innerText));
2731
});
28-
29-
// When registering a factory function 'this' refers to the GameObjectFactory context.
30-
//
31-
// There are several properties available to use:
32-
//
33-
// this.scene - a reference to the Scene that owns the GameObjectFactory
34-
// this.displayList - a reference to the Display List the Scene owns
35-
// this.updateList - a reference to the Update List the Scene owns

0 commit comments

Comments
 (0)