Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[RELEASED] Sprite Slicer - 'Fruit Ninja'-style sprite cutting system

Discussion in 'Assets and Asset Store' started by mrsquare, Nov 20, 2013.

  1. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Ah, I get you :) Not by default, I'm afraid - the algorithm just works with a 2D line so you can't assign any width to it. You could presumably create the same effect by making two parallel slices (the distance between them being the width you require) and then deleting any objects that lie in the area between the slices.
     
  2. Blightbuster

    Blightbuster

    Joined:
    Feb 14, 2017
    Posts:
    4
    Last edited: Dec 19, 2017
  3. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - do the sprites in the demo scene behave correctly?

    Stuff like this is often due to the import settings on the sprite texture - if you've got mipmaps enabled, try disabling them. If that doesn't work, feel free to email me a copy of your project (details should be in the readme file) and I can investigate.
     
  4. aditya_atthah

    aditya_atthah

    Joined:
    Dec 16, 2017
    Posts:
    2
    Hi, thanks for this awesome solution. I am using it make a fruit ninja type game and would really appreciate some help for adding multi touch support for slicing.
     
  5. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - there shouldn't be any changes required to the actual sprite slicer code in order to support multi-touch. Each slice just requires a start and end point, and doesn't know or care how those points are generated

    Its a bit old now, but this video might be of help in terms of showing you how to query the current touch position from the input system:
    https://unity3d.com/learn/tutorials/topics/mobile-touch/multi-touch-input.

    The demo code that comes with the asset shows how to add slices based on the mouse position, so you'd just need to do something similar to that, but using the touch position(s) instead of the mouse position.
     
  6. cmann

    cmann

    Joined:
    Aug 1, 2015
    Posts:
    31
    Hi. I have a question. How are you retrieving the sprite outlines?
    Not the physics shapes (which I think can be read with Sprite.GetPhysicsShape) but the outline for the sprite's mesh.
    I've tried "vertices", but that doesn't seem to be in any particular order.
     
  7. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - oof, its been ages since I wrote this! Just looking back over the code, I don't t think I really rely on the mesh vertices. Assuming a sprite is always a quad, the four vertices (in local coordinates) can be worked out using SpriteRenderer.bounds.min / SpriteRenderer.bounds.max, and the texture UVs from SpriteRenderer.sprite.textureRect. And if you want to get those points into world space, just translate them using transform.localToWorldMatrix.MultiplyPoint.
     
  8. cmann

    cmann

    Joined:
    Aug 1, 2015
    Posts:
    31
  9. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    I think you just can't see the sprite quad on the left hand banana, its only showing the collider.

    But yeah, the tool only really needs the original sprite dimensions in order to work out the texture UVs at all the vertices defined by the collision mesh. Once a sprite gets sliced, the original mesh is thrown away and the tool creates a new mesh that has a 1:1 mapping with the physics shape, and from then on the physics and visible mesh are exactly the same.
     
  10. cmann

    cmann

    Joined:
    Aug 1, 2015
    Posts:
    31
    Ah ok thanks again. I might have to take a similar approach.
    Though I have started working on pairing up triangle edges to build an outline from the sprite mesh as fun exercise.
    I'll have to see if it's worth the trouble/performance.

    (Sorry for hijacking your thread)
     
  11. sohaib_qadri

    sohaib_qadri

    Joined:
    May 19, 2014
    Posts:
    8
    Hi @mrsquare,

    Just wanted to ask if your asset will be able to slice the sprites that are using edge colliders?
     
    Last edited: May 3, 2021