Home > Net >  How to create new sprite 2d texture in the assets in the editor?
How to create new sprite 2d texture in the assets in the editor?

Time:11-29

the first problem is that i can't remember how i converted the image test to be sprtie 2d texture. the second problem is how to create a new empty sprite 2d texture ?

this is the script that should get the texture2d the source is fine but the destination i'm not sure what it should get in the editor.

at top :

public Texture2D source;
public Texture2D destination;
private int sourceMipLevel = 0;

and

private void testing()
    {
        // Get a copy of the color data from the source Texture2D, in high-precision float format.
        // Each element in the array represents the color data for an individual pixel.
        Color[] pixels = source.GetPixels(sourceMipLevel);
 
        // If required, manipulate the pixels before applying them to the destination Texture2D.
        // This example code reverses the array, which rotates the image 180 degrees.
        System.Array.Reverse(pixels, 0, pixels.Length);
 
        // Set the pixels of the destination Texture2D.
        int destinationMipLevel = 0;
        destination.SetPixels(pixels, destinationMipLevel);
 
        // Apply changes to the destination Texture2D, which uploads its data to the GPU.
        destination.Apply();
    }

screenshot of the image test and the sprtie 2d texture of the test that i can't remember how i created it and how to create the destination ?

test image as sprite 2d texture and as image

CodePudding user response:

In the editor, to convert a texture2D to a sprite, you need to change the box at the top called “Texture Type”. If you need to make an empty sprite in the editor, import your empty image and do the above. If you want to get a sprite from a Texture2D at runtime, Sprite.Create() will have your back. I don’t fully understand your question, but I hope this helps.

  • Related