- Home /
getting mip mapping to work on sprites
I can't seem to get mip maps to work for when i'm scaling down sprites in a 2d game.
It's the same problem in 2 different situations:
1) an ordinary sprite, becoming smaller when "zoomed out" by changing the scale on the camera
2) an Image in the new UI system, scaled down by having its RectTransform width and height set smaller
Should it work in both of these situations? I'm making the sprites in a script like this:
Texture2D texture = new Texture2D(4,4,TextureFormat.BGRA32,true);
//have tried all different kinds of settings for the following, none seem to help
texture.filterMode = FilterMode.Trilinear;
texture.mipMapBias = 8f;
texture.anisoLevel = 9;
texture.LoadImage(image);
Sprite sprite = Sprite.Create(texture, new Rect(0f,0f,texture.width,texture.height), new Vector2(.5f,.5f), 100.0f);
cell.transform.Find("Thumb").gameObject.GetComponent<Image>().sprite = sprite;
this is what an image of a grid looks like scaled down in unity:
and this is the same image scaled down properly (what i'd like it to look like):
is it impossible to do this with mip maps? if so is there another way you're supposed to do it? it must be possible! driving me mad...
EDIT:
I've managed to get both of the above situations working properly with mipmaps, by doing it with a test sprite in the editor rather than in a script. I.e. i turned mipmaps on in the image file's import settings.
But for my game i need to do it in a script (to import hundreds of sprites). Does anyone know if it should work? I would have thought that creating the texture with the last parameter set to true would be equivalent to turning mipmaps on in the texture import settings?
additionally, in the import settings in the editor, i see an option for "in linear space" - where is the equivalent for this in the Texture2D class?
Your answer
Follow this Question
Related Questions
Can't change Image sprite because in rebuild loop? 2 Answers
Unity 4.6's button Bug? 1 Answer
How to add callback for button press to a private function (New UI)? 1 Answer
Unity 5.0 Trying to Change the Image - Source Image via Script 3 Answers
How to make a UI image change sprite through a script that is not attached to the UI image itself 0 Answers