Skip to content

Commit

Permalink
spawn objects correctly, with an iterator cb
Browse files Browse the repository at this point in the history
  • Loading branch information
englercj committed Oct 4, 2014
1 parent 88e2b56 commit 5f17fe6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/tiled/Objectlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module.exports = Objectlayer;
* @return {Objectlayer} Returns itself.
* @chainable
*/
Objectlayer.prototype.spawn = function () {
Objectlayer.prototype.spawn = function (spawnCallback) {
// we go through these backwards so that things that are higher in the
// list of object gets rendered on top.
for(var i = this.objects.length - 1; i >= 0; --i) {
Expand Down Expand Up @@ -163,11 +163,10 @@ Objectlayer.prototype.spawn = function () {

// just a regular DisplayObject
if (!props.texture) {
obj = new Phaser.Group();
obj = this.game.add.group(this.container, o.name);

obj.width = o.width;
obj.height = o.height;
obj.name = o.name;
obj.rotation = o.rotation;
obj.objectType = o.type;

Expand All @@ -180,15 +179,13 @@ Objectlayer.prototype.spawn = function () {

// obj.enablePhysics(this.game.physics);
} else {
props.width = o.width;
props.height = o.height;
obj = this.game.add.sprite(o.x, o.y, props.texture, null, this.container);

obj = this.map.spritepool.create(o.type, props.texture, props);
// obj.width = o.width;
// obj.height = o.height;

obj.name = o.name;
obj.type = o.type;
obj.position.x = o.x;
obj.position.y = o.y;
obj.objectType = o.type;

// obj.mass = props.mass || props.tileprops.mass;
// obj.inertia = props.inertia || props.tileprops.inertia;
Expand Down Expand Up @@ -282,7 +279,10 @@ Objectlayer.prototype.spawn = function () {
}

obj._objIndex = i;
this.container.addChild(obj);

if (spawnCallback) {
spawnCallback(obj);
}
}

return this;
Expand Down
4 changes: 2 additions & 2 deletions src/tiled/Tilemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,9 +802,9 @@ Tilemap.prototype.postUpdate = function () {
* @return {Tilemap} Returns itself.
* @chainable
*/
Tilemap.prototype.spawnObjects = function () {
Tilemap.prototype.spawnObjects = function (spawnCallback) {
for(var i = 0, il = this.objects.length; i < il; ++i) {
this.objects[i].spawn();
this.objects[i].spawn(spawnCallback);
}

return this;
Expand Down

0 comments on commit 5f17fe6

Please sign in to comment.