isfuturebright Posted November 4, 2013 Share Posted November 4, 2013 How can I added new collision boxes for the same sprite? I currently have my player class that extends Phaser.Sprite which has the body property for collision. Link to comment Share on other sites More sharing options...
rich Posted November 4, 2013 Share Posted November 4, 2013 The short answer is that you can't. I would suggest looking at something like p2.js or chipmunk if you need advanced body management, it should be relatively easy to hook that in to control sprite placement. Link to comment Share on other sites More sharing options...
isfuturebright Posted November 4, 2013 Author Share Posted November 4, 2013 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 More sharing options...
rich Posted November 4, 2013 Share Posted November 4, 2013 Fair enough, I guess the only constraint with this approach is that you've got no, well.. constraints Ideally all of parts of the body object would be attached together (via a spring, joint, distance constraint, etc), but hey if this works for you then great isfuturebright 1 Link to comment Share on other sites More sharing options...
Recommended Posts