Jump to content

Multiple Collision Boxes


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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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