Jump to content

Convex hull sprites?


Ponsol
 Share

Recommended Posts

  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 GIn6Kif.png.

 

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

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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