开发者

Multiple cpShapes (chipmunk)

So I have created two shapes( poly's to be exact) and I need to be able to attach them to a single CCSprite/image, and have them stay in the position that I have created them at. Is there any way to do that?

So in short this is what I am trying to achieve.

  • I have a tire (CCSprite/image) and I have created 2 poly's/cpShapes, one for the top and one for the bottom of the tire so that when the user throws a football it can only go through the center of it.
  • I need to attach the top poly to the top of the tire and the bottom poly to the bottom of the tire
  • I also need to be able to use collision on the tire. For instance if the user throws the football and it hits the bottom of the tire, I need to be able to make the tire sway back and forth with both shapes moving with it.

So my question is really only how can I attach two cpShapes to one image/CCSprite?

I have created my shapes like so:

cpShape *UpperShape = [game.spaceManager addPolyAt:c开发者_StackOverflow社区pv(70,195) mass:STATIC_MASS rotation:0 numPoints:6 points:cpv(2,12), cpv(28,8), cpv(33,0), cpv(36,-10), cpv(-33,-10), cpv(-20,8)];

cpShape *LowerShape = [game.spaceManager addPolyAt:cpv(70,125) mass:STATIC_MASS rotation:0 numPoints:7 points:cpv(34,8), cpv(31,0), cpv(25,-9), cpv(7,-13), cpv(-20,-8), cpv(-30,0), cpv(-35,8)];

P.S I am using spaceManager+chipmunk


Basically, you create a single cpBody, and attach the 2 cpShape's to it. Using ccPhysicsSprite allows you to attach a sprite to a body, which is the result you're trying to get.


Unless spaceManager is doing something for you, it's up to you to determine how cpShapes and CCSprites attach. All I would do is subclass CCSprite and override -draw. In the -draw function update the position and rotation of the sprite to the center of the two shapes combined.

It would probably be easier to make two sprites and attach one sprite to one shape though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜