Cut it Devlog – Part 2 – The Mechanism of Cutting

In the previous post, i just provided a background of how the creation of Cut-it began. But even at the point of developing a working prototype, i haven’t had any idea of developing a full game with it. That came later, which i don’t know when. Anyway lets get into the details of cutting. I’ll be going through the ideas here, not code. And this isn’t related to the idea of  emmanuelle fernato. So here it is.

1. I wanted to cut the Body A into two pieces, B and C, along the line EF.


2. First I need to get the intersection points the line makes on the shape. I check each edges of the polygon with the line using some code found on web for line to line intersection. I call the points x & y.


3. And i create bodies B and C with corresponding vertices 0-x-y-3 and x-1-2-y.


4. And Voila, we get 2 bodies sliced using a line.

Nape Physics Implementation (Box2D too, i think)

But, wait. How do we implement that using Nape Physics engine ?

1. In Nape, each body has a polygon shape. Each polygon Shape has a World Vertices (polygon.worldVerts) from which we will get 0-3 or more if it has more sides.

2. The co-ordinates of EF is obtained through mouse listeners on Mouse Press & releasing.

3. I check for intersection for EF and 01, 12, 23, 30 (edges) and check whether its intersecting or not.

4. I create 2 points list, one for bodyB and another for bodyC (Each list containing vertices 0-x-y-3 and x-1-2-y).

5. For each list i find the centroid and place the new bodies in that point (shapes not added yet).

6. Now we create polygon with the points and add the polygon to each body.

7. Add this bodies to space and remove the main body from space.


This might be hard to understand a bit, but i suggest you try familiarizing with the physics engine before trying this. Its fun to cut things in physics.

But i haven’t touched upon many upcoming challenges ahead that arises when things started to seem working well. That’s for the next blog post. Comment on how to improve this, anything you want to explain in deep etc.

Cut it Devlog Series

Part I – The Beginning

Part II – The mechanism of Cutting

Part IX – Converting Starling to Native Flash

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *