Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by AarnasS75 · Jul 14, 2020 at 08:14 AM · unity 2dscalespritesstretching

How to stretch a sprite without distortion ?

What is the best way to go about this? What I'm trying to do, is to stretch the object along the X axis while the finger is touching the screen and when the finger is lifted the object falls down. The problem is that my script works fine when a solid color is applied (red, white, black, etc. ), but when I try to import some custom sprites, for example planks, the sprite quality distorts, because of stretching. Is there a way to maintain the same quality when the sprite is stretched ? I think the way to go about this is to use solid color while it is stretching and after the finger is released apply the sprite, but I have no idea how to achieve this. alt text


alt text

Script:

 public class Extend : MonoBehaviour
 {
     public float speed = 0.2f;
     Rigidbody2D rb;
     public GameObject line;
 
     bool TouchInputOff = false;
     private void Awake()
     {
         rb = GetComponent<Rigidbody2D>();
     }
     private void Update()
     {
         if (!TouchInputOff)
         {
             if (Input.GetMouseButton(0))
             {
                 line.transform.localScale = new Vector3(transform.localScale.x + 0.2f * speed, transform.localScale.y, 0);
             }
             if (Input.GetMouseButtonUp(0) || line.transform.localScale.x >= 5.0f)
             {
                 rb.gravityScale = 3;
                 TouchInputOff = true;
             }
         }
         else
         {
             rb.gravityScale = 3;
         }
     }
 }

stretched-plank.jpg (22.9 kB)
original-plank.jpg (10.3 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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by tuinal · Jul 14, 2020 at 02:19 PM

You need to set up the sprite for 9-slicing, since what you effectively want is the middle part to tile, and the corners to stay as they are. Unity can do this for you in the Sprite Editor, but you need a sprite with a central texture that's tileable for a good visual end-result.

https://docs.unity3d.com/Manual/9SliceSprites.html

Comment
Add comment · Show 1 · Share
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
avatar image AarnasS75 · Jul 15, 2020 at 07:24 AM 0
Share

Thank you, I'll try this out

avatar image
0

Answer by sachinchetu · Jul 20, 2020 at 11:37 AM

Yes, you can cut sprite in three-part and whenever you need to stretch it just add middle part in your sprite, don’t change the order of these sprites –Starting part > Middle part > Ending Part and it will work for you like this- Starting part > Middle part1 > Middle part2>…….. >Middle partN> Ending Part. @AarnasS75

Comment
Add comment · Share
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

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

144 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 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

How to fit a background sprite with 4:3 aspect ratio in a 16:9 screen by simply making the extra content of the sprite from the bottom go outside the camera? 2 Answers

My Game Screen Scale keeps jumping to 1x when I start the game? 1 Answer

Does Unity 2D tools generate atlas? 1 Answer

How to add material/texture to basic Sprite? 1 Answer

Why Sprites see ok in preview and not in Android or Android Emu? 0 Answers


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