Jump to content

Multiple Collision Boxes


isfuturebright
 Share

Recommended Posts

OK so I took a decision before reading your answer here. I basically modified/added some functions for it:

//On the Phaser.Spritethis.collisionBoxes = new Array(); //Added new variable in the constructor//Function to add new collision boxes to be updated and handle inside the Phaser.SpritePhaser.Sprite.prototype.addCollisionBox = function(){	var nColBox = new Phaser.Physics.Arcade.Body(this);	this.collisionBoxes.push(nColBox);	return nColBox;}//Then I added them where the Sprite.Body was, like Pre-Update, reset...//I also added a renderBody since there was only a renderSpriteBody optionrenderBody: function (body, color) {        if (this.context == null)        {            return;        }        color = color || 'rgba(255,0,255, 0.3)';        this.start(0, 0, color);        this.context.fillStyle = color;        this.context.fillRect(body.screenX, body.screenY, body.width, body.height);        this.stop();    },
//Later on my player class constructorthis.leftShoulder = this.addCollisionBox();this.leftShoulder.setSize(20, 10, 150, 70);//On the game state I can now do:if(Phaser.Rectangle.intersects(this.player.leftShoulder, this.ball.body))    this.ballHitsPlayer(this.ball, this.player); 

So far it's working kinda like a need without fuss, but I'll be checking out what you said. I don't need anything too complex really it's because I'll need to know whether it hit a specif part of the body of the sprite I have.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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