- Home /
How to crop sprite during runtime?
I don't know if this is possible, but I figured i'd ask anyway. I have an 8x8 image, and I'm wondering if while the game is running I can crop out the image so only the 1x8 column on the rightmost part of the image is showing. (Deleting the pixels located in the 7x8 area of the leftside of the image) BTW, resizing the image so it is the size of a 1x8 column is not ideal for my situation.
Answer by rlo · Oct 27, 2015 at 07:24 AM
Try using UI image, change the image type to Filled, change the fill method to Horizontal, change the Fill origin to Right ,change the Fill amount to 1/8 or 0.125.
image.GetComponent<Image>().fillAmount = .125f;
Answer by GiyomuGames · Oct 27, 2015 at 08:09 AM
You can define a 1x8 sprite (and 2x8 etc.) on your 8x8 image. Then at runtime you just have to chose which sprite you want to display.
Your answer
Follow this Question
Related Questions
Making the enemy follow the path of the Player,How to make the enemy follow the path of the player? 0 Answers
Changing the orthographicSize of the camera to make sure play field fits 0 Answers
How do I stop my sprite from jumping in the air? 1 Answer
Instantiate a GameObject with a specific Z rotation 2 Answers
2D Sprite Fillup without using UI 1 Answer