Jump to content

Adjust arcade body bounds


powerfear
 Share

Recommended Posts

Is it possible to adjust the body of a sprite so that it take the sprite frame and angle into account? I have a couple of animated sprites who have different frame sizes while playing the animations but the change are not reflected on the body. Same deal with the sprite angle, if i change the angle the body bounds will be wrong. I kind of solved the animation issue by adding my own new method to the arcade body:

betterUpdateBounds: function() {        this.width = this.sprite.width;        this.height = this.sprite.height;        this.halfWidth = Math.floor(this.width / 2);        this.halfHeight = Math.floor(this.height / 2);        this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);        //this.offset.x = (this.sprite.anchor.x * this.width);        //this.offset.y = (this.sprite.anchor.y * this.height);}
This work partially, but if I use anchor 0.5 for example, I need to set the offsets again to take into account the new frame width/height, but this seem to cause the sprite to shake. Also this still doesn't solve the angle issue.
 
Am I on the right track or am I doing this completely wrong? Should I use another physic system instead?
Link to comment
Share on other sites

Nevermind, I ended up using a simple rectangle intersect check since I only need to check a few number of objects for overlap it worked great.

for (var i = 0; i < this.group1.length; i++) {	for (var j = 0; j < this.group2.length; j++) {		var entity1 = this.group1.children[i];		var entity2 = this.group2.children[j];		if (entity1.alive && entity2.alive) {			if (entity1.getBounds().intersects(entity2.getBounds())) {				this.entityCollide(entity1, entity2);				return;			}		}	}}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...