Skip to content

Commit

Permalink
[#560] fixed body default initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
obiot committed Aug 21, 2014
1 parent 25de332 commit 3e17608
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/entity/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@
// add collision shape to the entity body if defined
if (typeof (settings.getShape) === "function") {
this.body.addShape(settings.getShape());
} else {
// else make the body bounds match the entity ones
this.body.updateBounds(new me.Rect(0, 0, this.width, this.height));
}

// ensure the entity bounds and pos are up-to-date
this.updateBounds();

// set the collision mask if defined
if (typeof(settings.collisionMask) !== "undefined") {
this.body.setCollisionMask(settings.collisionMask);
Expand Down
18 changes: 10 additions & 8 deletions src/physics/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,11 @@
// call the super constructor
this._super(
me.Rect,
// bounds the body by default
// to the parent entity
"init", [
entity.pos.x,
entity.pos.y,
0,
0,
entity.width,
entity.height
]
Expand Down Expand Up @@ -312,12 +314,12 @@
* @function
*/
updateBounds : function (rect) {
// reset the body position and size;
this.pos.set(0, 0);
this.resize(0, 0);
// TODO : go through all defined shapes
this.union(rect || this.getShape().getBounds());

var _bounds = rect || this.getShape().getBounds();
// reset the body position and size;
this.pos.setV(_bounds.pos);
this.resize(_bounds.width, _bounds.height);

// update the parent entity bounds
this.entity.updateBounds();
},
Expand Down Expand Up @@ -615,7 +617,7 @@

// update player entity position
this.entity.pos.add(this.vel);
this.entity.updateBounds();
this.updateBounds();

// returns the collision "vector"
return collision;
Expand Down

0 comments on commit 3e17608

Please sign in to comment.