📜 ⬆️ ⬇️

Rope like in “Cut the Rope”

After reading the interview with the creators of the famous bestseller “Cut the Rope”, which states that they spent the most time on creating the rope, I did not believe that it was really so difficult to write an algorithm for moving a heavy thread, and for this you need almost write physics engine. Googling, I did not find a ready answer, and decided to try to do something similar on cocos2D + Box2D myself .
The rules were based on:
  1. It is better to do a chain with the help of rectangular bodies connected by the Revolution Joint'ami;
  2. The heavier the objects that make up the chain, the more stable it is;
  3. The number of iterations at a step - the more, the better (3 was enough for me);
  4. It helps if every piece of the chain, in addition to the Revolution Joint, connects the 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, it was not difficult to make a heavy thread in Box2D.
It remains to describe the graphic part. This, of course, should have been helped by 2-order Bezier curves, the algorithm of which is already implemented in DrawingPrimitives in cocos2D.
To find the points for drawing curves, you can use Revolution Joint's joints, which I did. However, the result of the work I was very upset, I received a terrible pixeliretization, which is clearly seen in the following graphic materials:
image


Unfortunately, it is impossible to use anti-aliasing in cocos2D without OpenGL ES 2.0 support (it wasn’t necessary 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's what happened in the end:
image
')

Thus, the development of a “heavy thread motion algorithm” took me no more than 14 hours.
The line anti-aliasing drawing code is attached.
ccDrawingPrimitives.zip

Used here and here .

Source: https://habr.com/ru/post/135338/


All Articles