Ponsol Posted June 4, 2015 Share Posted June 4, 2015 How can I represent a circle using the convex hull? I want it to behave as a blob http://hakim.se/experiments/html5/blob/03/ like this but I don't know where to start. Any help will be much appreciated Link to comment Share on other sites More sharing options...
Ponsol Posted June 4, 2015 Author Share Posted June 4, 2015 game.physics.startSystem(Phaser.Physics.P2JS); b1 = game.add.sprite(430,400, 'food'); b2 = game.add.sprite(430,400, 'food'); b3 = game.add.sprite(430,400, 'food'); b4 = game.add.sprite(430,400, 'food'); b5 = game.add.sprite(430,400,'food'); b6 = game.add.sprite(430,400,'food'); b7 = game.add.sprite(430,400,'food'); b8 = game.add.sprite(430,400,'food'); game.physics.p2.enable([b1,b2,b3,b4,b5,b6,b7,b8]); var bs = [b1,b2,b3,b4,b5,b6,b7,b8]; for (var i = 0; i<bs.length; i++ ){ game.physics.p2.createSpring(bs[i],bs[(i+1)%bs.length], 40,500); game.physics.p2.createSpring(bs[i],bs[(i+2)%bs.length], 40,500); game.physics.p2.createSpring(bs[i],bs[(i-1+bs.length)%bs.length], 40,500); game.physics.p2.createSpring(bs[i],bs[(i-2+bs.length)%bs.length], 40,500); }A really ugly mock up that I'm trying to get to work. I'm using springs to attach a sprite to 4 other sprites as I'm trying to get it to replicate this behaviour . It behaves well when I give it 5 points as they all form a pentagon but any more than that and the sprites form weird shapes instead of regular polygons. I was thinking if it would be possible to do what I'm doing above but, instead of working on sprites, using phaser's polygon and applying the physics onto each point. Is that something that's possible? If that's not possible I'll have the problem of representing the group sprites that I'm loading in as one circle which I don't know how to do. Thoughts anyone? Link to comment Share on other sites More sharing options...
Ponsol Posted June 7, 2015 Author Share Posted June 7, 2015 bump Link to comment Share on other sites More sharing options...
Recommended Posts