1
votes

I'm developing a game on iOS w/ cocos2d+box2d as the game engine, and am trying to add a CCRibbon (wherein the points get populated with touches), that I know how to, and to get that CCRibbon's shape linked up to box2d, so when an object collides with it (due to gravity), it bounces off as if it were a normal thing. Would anyone happen to know how to do this / give me alternatives ? Many thanks, Alexandre Cassagne

2

2 Answers

1
votes

Take each point and create a thin static rectangular box2d polygon using the points + the adjustment to make it a shape.

for (int i = 0; i < ccribbon.points.length - 1; i++)
{
    int j = i;
    j++;
    int width = 2;

    Array ar = [];
    ar[0] = new b2Vec2(ccribbon.points[i].x, ccribbon.points[i].y);
    ar[1] = new b2Vec2(ccribbon.points[i].x + width, ccribbon.points[i].y + width);
    ar[2] = new b2Vec2(ccribbon.points[j].x, ccribbon.points[j].y);
    ar[3] = new b2Vec2(ccribbon.points[j].x + width, ccribbon.points[j].y + width);

    //create new static object
    b2Polygon b2p = new b2Polygon();
    b2p.setAsArray(ar);

    //do rest to add it to world etc.

}

of course don't copy that code exactly its just from what i remember and i'm also sure its a combination of C# and Actionscript 3. its kindof a not so pseudo code with lots of blanks you'll need to fill in. Why the comments are there :P.

Thats basically how i would do it though. My experience is only in box2d for flash though.