Rope like in “Cut the Rope”

    After reading an interview with the creators of the famous bestseller “Cut the Rope”, which claims that they spent the most time creating the rope, I did not believe that writing “heavy thread movement algorithm” is really so difficult, and for this we need almost write a physics engine. Googling, I did not find a ready answer, and decided to try to do something similar myself on cocos2D + Box2D .
    The rules were taken as a basis:
    1. The chain is better done using rectangular bodies connected by Revolute Joints;
    2. The heavier the objects that make up the chain, the more stable it is;
    3. The number of iterations per step - the more the better (3 were enough for me);
    4. It helps if every piece of the chain, in addition to the Revolute Joint, is connected by a Distance Joint.


    As a result, I got a chain of objects in the physical world, the result can be seen in the following figure and video:
    image


    Thus, making heavy thread in Box2D was not difficult.
    It remains to describe the graphic part. This, of course, should be helped by Bezier curves of 2 orders, the algorithm of which is already implemented in DrawingPrimitives in cocos2D.
    To find the points for drawing the curves, you can use the connection points of the Revolute Joints, which I did. However, the result of the work done made me very upset; I got terrible pixelation, which is clearly visible in the following graphic materials:
    image


    Unfortunately, you cannot use antialiasing in cocos2D without support for OpenGL ES 2.0 (I did not want to use it with support, for objective reasons), so the method was used to eliminate the unpleasant effect .
    The result I was completely satisfied, moreover, after a long study of the difference between my ropes and in “Cut the Rope”, I did not notice this. Here is the result:
    image


    Thus, it took me no more than 14 hours to develop a “heavy thread movement algorithm”.
    The code for drawing anti-aliasing lines is attached.
    ccDrawingPrimitives.zip

    Used here and here .

    Also popular now: