Hello Guest

Author Topic: Sprite Slicer 2D - Fruit Ninja-style sprite cutting system  (Read 12776 times)

mrsquare

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Sprite Slicer 2D - Fruit Ninja-style sprite cutting system
« on: November 20, 2013, 10:20:01 am »
Hi folks,

I'm pleased to announce the release of Sprite Slicer 2D on the Unity Asset Store :)

Web Player

Tutorial Video

Sprite Slicer 2D allows you to cut any physics enabled sprite into little pieces, each of which then behaves as its own independent physics object. Its perfect for bringing your 2D game to life with destructible objects and environments, or for creating a Fruit-Ninja style cutting game.

* Works on both Unity and 2D Toolkit sprites.
* Simple static script functions allow you to slice sprites along a given line, or explode them into multiple parts.
* Optimised to preserve dynamic batching and reduce draw calls.
* Slices any sprite with a 2D box, circle or convex polygon collider
* Full C# source code and example scene included


The code has been designed to be as transparent as possible - there are no new gameobjects to create; you simply pass a cut start and cut end point to one of the static Sprite Slicer 2D functions, and the code will handle the rest. Once cut, each child sprite behaves as its own separate physics body, retaining all the physics and rendering properties of the parent object, and can itself be cut into further child objects. If required, the slicing functions can return a list of all the cut objects along with their child objects and cut positions, so that the user's code can perform additional processing once the cut has taken place. Equally, you can delay destruction of the parent object in the event that you need to access variables from it before it is destroyed.




I hope this proves helpful to some people out there! Please feel free to reply in this thread or PM me if you have any questions :)
« Last Edit: December 04, 2013, 09:56:13 am by mrsquare »

mrsquare

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Sprite Slicer 2D - Fruit Ninja-style cutting system
« Reply #1 on: November 21, 2013, 05:17:12 pm »
Some guys over on Reddit were asking for some example of the interface, so this might be of interest to some folk here too:

Code: [Select]
static void SliceAllSprites(Vector3 worldStartPoint, Vector3 worldEndPoint);
static void SliceAllSprites(Vector3 worldStartPoint, Vector3 worldEndPoint, bool destroySlicedObjects, ref List<SpriteSlicer2DSliceInfo> slicedObjectInfo);
static void SliceSprite(Vector3 worldStartPoint, Vector3 worldEndPoint, GameObject sprite);
static void SliceSprite(Vector3 worldStartPoint, Vector3 worldEndPoint, GameObject sprite, bool destroySlicedObjects, ref List<SpriteSlicer2DSliceInfo> slicedObjectInfo);

So you have the option of slicing any sprite that intersects the vector or you can pass through a specific gameobject if you know exactly what it is that you want to cut. The demo is using the first option, which is why you can get multiple things getting cut if you move the mouse fast enough.

SpriteSlicer2DSliceInfo is an optional parameter, which will get filled out with information on which slice generated which child objects from which parent object, so you can do any extra processing as required (eg. add particle effects at the cut positions, increment a score depending on what type of object the parent was)

The explosion code is as follows:

Code: [Select]
static void ExplodeSprite(GameObject sprite, int numCuts, float explosionForce);
static void ExplodeSprite(GameObject sprite, int numCuts, float explosionForce, bool destroySlicedObjects, ref List<SpriteSlicer2DSliceInfo> slicedObjectInfo);

It basically slices the object multiple times at random angles through the centre, and then applies an outward force to each child object away from the centre. I've got some ideas for improving this - specifically running a triangulation algorithm over the mesh and then creating the child objects from that. Should make a more pleasing shattering type effect with more evenly distributed polys (its a bit 'chunky' at the moment).

mrsquare

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Sprite Slicer 2D - Fruit Ninja-style sprite cutting system
« Reply #2 on: December 04, 2013, 10:00:52 am »
Have added a little tutorial video to the first post :)

sengsongfx

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • บาคาร่าจีคลับ
Re: Sprite Slicer 2D - Fruit Ninja-style sprite cutting system
« Reply #3 on: August 03, 2015, 10:41:31 am »
I have no intention strongly, with members who have come here.