So after this very poor pun It’s time for my question.
I’m currently creating a fruit ninja clone and my goal is to cut the thrown fruits into smaller pieces. For slicing the physics body I use the code that I found in the Slice demo in the cpp-tests. This stuff works really good but the problem I have is that it only cuts the physics body, not the sprite that it’s associated with.
I think if it were me I’d slice the sprite using the same points from the swipe as slicing the physics body. They should be the same dimension. Maybe Clipping Node the sliced pieces to just show what was left after cutting or make a new Texture from it and replace the Sprite with the cut piece?
I’m not sure about the whole “physics body cutting” thing, but I’d go with a ClippingNode. I’d have each fruit as a ClippingNode with the fruit sprite added to it and when it’s cut add a second ClippingNode with the fruit sprite as a child. I’d probably use a DrawNode to define the area left after the cut to draw for each ClippingNode.
Not sure about this, but I’m pretty sure you can change the shape of a sprite by changing its PolyInfo or PolygonInfo. It might be possible to change this and the area of the texture the sprite uses to show only one part of the cut fruit and add a second Sprite with its polygon info set to show the other part of the fruit. I’d suspect that might be more efficient than using ClippingNodes.
If you don’t care about your fruit being cut exactly along the exact line you moved your finger, the easiest method is to have 1 sprite with the whole fruit and then 2 sprites that are fruit cut in half. Then when the fruit is cut, just replace the sprite of the whole fruit with the 2 sprites of the fruit cut in half.
@grimfate
Thanks! I think I will go for now with the simple solution as the deadline is around the corner
I have one more question regarding this. How would You calculate if the object has been cut? I have only _startPoint and _endPoint of the cut (so basicaly a line) and a physicbody (for now a circle one but this will change). How do I know if those two points cut through the whole body?
EDIT: Wait, this was a dumb question. I already have it with the slice method from the tests Questions like this occur when You try to think to much while the solution is right in front of You. Sorry.