Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by IslamUni · Aug 26, 2017 at 11:17 AM · spritepositioningcutting

How to position Sprite sliced/cut parts?

Hello everyone, I'm working on this sprite slicer mechanics and everything is finished except for the positioning of the two cut objects so help with this please. The code is too much to place here so I'm going to share what's relevant to the issue, This is the main function to get an idea of the workflow.

 public void SliceSprite(Vector2 hitPointA, Vector2 hitPointB, GameObject obj)
         {
             SpriteRenderer spriteR = obj.GetComponent<SpriteRenderer>();
             Vertices originCornerPoints;
             Vertices newCornerPoints;
             Sprite originSp, newSp;
 
             // Transforming points from global to local;
             hitPointA = obj.transform.InverseTransformPoint(hitPointA);
             hitPointB = obj.transform.InverseTransformPoint(hitPointB);
 
             // Get vertex set for both old and new sprite AND create sprite pieces from the original.
             FindPathWithRectangleCorners(hitPointA, hitPointB, out originCornerPoints, out newCornerPoints, out originSp, out newSp, spriteR);
 
 
             // Closing the polygon with the line that forms a convex.
             SealPolygon(ref originCornerPoints, hitPointA, hitPointB, spriteR.sprite, originSp);
             SealPolygon(ref newCornerPoints, hitPointA, hitPointB, spriteR.sprite, newSp);
 
 
 
             // Sort vertices to shape outlines
             originCornerPoints = SortVertices(originCornerPoints);
             newCornerPoints    = SortVertices(newCornerPoints);
 
 
             // Build the required texture polygon based on the slice line.
             OverrideSpriteGeometry(originCornerPoints, originSp);
             OverrideSpriteGeometry(newCornerPoints, newSp);
 
 
             // Creat sliced sprites
             DeploySlices(obj, spriteR.sprite, originSp, newSp);
         }

and here is where the problem occurs (testing on vertical cuts only).

 private void DeploySlices(GameObject obj, Sprite mainSprite, Sprite originSp, Sprite newSp)
         {
             int flipX = obj.GetComponent<SpriteRenderer>().flipX ? -1 : 1;
             int flipY = obj.GetComponent<SpriteRenderer>().flipY ? -1 : 1;
 
             // Create a new gameobject to carry the smallest slice of the sprites.
             GameObject go = new GameObject("Slice");
             //go.transform.SetParent(obj.transform, false);
             go.transform.localScale = obj.transform.localScale;
             go.transform.position   = obj.transform.position;
             go.AddComponent<SpriteRenderer>();
             go.GetComponent<SpriteRenderer>().flipX = obj.GetComponent<SpriteRenderer>().flipX;
             go.GetComponent<SpriteRenderer>().flipY = obj.GetComponent<SpriteRenderer>().flipY;
 
             float value1 = 0.0f, value2 = 0.0f;
 
             value1 = mainSprite.rect.width - originSp.rect.width;
             value1 *= flipX;
             go.transform.position += new Vector3(value1, 0);
 
             go.GetComponent<SpriteRenderer>().sprite = originSp;
 
             mainSprite = null;
         }

a display sample of the current positioning approach drawn on top of the original sprite for comparison.

alt text

ask if there is any ambiguity, thank you.

capture.jpg (24.1 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

93 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Positioning sprite perfectly in camera view. 0 Answers

How to adjust positions of the sprites to different screen factors? 2 Answers

Calculate sprite positioning 0 Answers

How can I load and position my sprites in c#? 1 Answer

Cutting sprite instead of stretching 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges