- Home /
Resize a sprite by giving it more transparent pixels
I have a sprite the size of 402X188. I wish to use DTX5 format so I will probably need 404X188 to make it use the compression I mentioned. Now, I got to know about this feature a wee bit too late and I have a whole bunch of textures in place for my game. I'm trying to get around this using some simple code like so:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ResizeSprites
{
public void Resize(Sprite sprite)
{
int _dimensions = 2;
int greaterOldDim = Mathf.RoundToInt(Max(sprite.rect.width, sprite.rect.height));
for (int i = 2; i <= greaterOldDim*2; i*=2)
{
_dimensions = i;
}
sprite.texture.
Resize(_dimensions, _dimensions,TextureFormat.RGB24, false);
}
private float Max(float a, float b){return a > b ? a : b;}
}
And needless to say it doesn't work. If I try to change TextureFormat
to DTX5
it says can't resize to a compressed texture format
. Currently it generates a completely empty texture (that's size is the power of 2, will adjust that). So, how to modify a sprite's size by code by basically adding transparent pixels to it?
texture's import settings have to have read/write enabled in the inspector to do what you are talking about and i don't think sprite textures have this option!!!!!
Idk what issues you will face or how you will overcome them but it I do believe you have to call TExture.apply() on any texture you change.