Skip to content

Commit 1c68ff9

Browse files
committed
Tilemap.createFromObjects allows you to specify you own object type to be created if you want a class that extends Phaser.Sprite.
1 parent a51ae03 commit 1c68ff9

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/tilemap/Tilemap.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,16 @@ Phaser.Tilemap.prototype = {
310310
* @param {string} key - The Game.cache key of the image that this Sprite will use.
311311
* @param {number|string} [frame] - If the Sprite image contains multiple frames you can specify which one to use here.
312312
* @param {boolean} [exists=true] - The default exists state of the Sprite.
313-
* @param {boolean} [autoCull=true] - The default autoCull state of the Sprite. Sprites that are autoCulled are culled from the camera if out of its range.
314-
* @param {Phaser.Group} [group] - Optional Group to add the Sprite to. If not specified it will be added to the World group.
313+
* @param {boolean} [autoCull=false] - The default autoCull state of the Sprite. Sprites that are autoCulled are culled from the camera if out of its range.
314+
* @param {Phaser.Group} [group=Phaser.World] - Group to add the Sprite to. If not specified it will be added to the World group.
315+
* @param {object} [objectClass=Phaser.Sprite] - If you wish to create your own class, rather than Phaser.Sprite, pass the class here. Your class must extend Phaser.Sprite and have the same constructor parameters.
315316
*/
316-
createFromObjects: function (name, gid, key, frame, exists, autoCull, group) {
317+
createFromObjects: function (name, gid, key, frame, exists, autoCull, group, objectClass) {
317318

318319
if (typeof exists === 'undefined') { exists = true; }
319-
if (typeof autoCull === 'undefined') { autoCull = true; }
320+
if (typeof autoCull === 'undefined') { autoCull = false; }
320321
if (typeof group === 'undefined') { group = this.game.world; }
322+
if (typeof objectClass === 'undefined') { objectClass = Phaser.Sprite; }
321323

322324
if (!this.objects[name])
323325
{
@@ -331,17 +333,21 @@ Phaser.Tilemap.prototype = {
331333
{
332334
if (this.objects[name][i].gid === gid)
333335
{
334-
sprite = group.create(this.objects[name][i].x, this.objects[name][i].y, key, frame, exists);
336+
sprite = new objectClass(this.game, this.objects[name][i].x, this.objects[name][i].y, key, frame);
335337

336338
sprite.anchor.setTo(0, 1);
337339
sprite.name = this.objects[name][i].name;
338340
sprite.visible = this.objects[name][i].visible;
339341
sprite.autoCull = autoCull;
342+
sprite.exists = exists;
343+
344+
group.add(sprite);
340345

341346
for (property in this.objects[name][i].properties)
342347
{
343348
group.set(sprite, property, this.objects[name][i].properties[property], false, false, 0);
344349
}
350+
345351
}
346352
}
347353

0 commit comments

Comments
 (0)