Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity Texture2D efficient performance draw pixels

var pixels = myTexture.GetPixels32();
for (int i = 0; i < pixels.Length; i++) 
{
    pixels[i] = Color.black;
}
    
    // Draw ants
foreach (Ant ant in ants)
{
    for (int i = 0; i < cellSize; i++)
    {
        for (int j = 0; j < cellSize; j++) 
        {
            // TODO: calculate the index of the pixel in the flat array
            // Not 100% sure on that one tbh ;)
            var index = (ant.thisX * cellSize + i) + myTexture.width * (ant.thisY * cellSize + j);
            
            pixels[index] = Color.white
        }
    }
}

myTexture.SetPixels32(pixels);

myTexture.Apply();
Comment

PREVIOUS NEXT
Code Example
Csharp :: cache.TryGetValue in MemoryCache c# .net 
Csharp :: player ToJson unity 
Csharp :: calculator using single readline c# 
Csharp :: cannot access file being used by another process create file 
Csharp :: windows 10 see how long a program has been running 
Csharp :: C# Project File Create 
Csharp :: c# stack 
Csharp :: commandline to open outlook minimized 
Csharp :: convert array to datatable c# 
Csharp :: 2d look at unity 
Csharp :: prime number in c# 
Csharp :: get position of gameobject unity 
Csharp :: c# list with only unique items 
Csharp :: c# loop backwards 
Csharp :: c# count items in listbox 
Csharp :: unity trigger not detecting collision 
Csharp :: c# filesystemwatcher 
Csharp :: can lightning strike the same place twice 
Csharp :: how to mirror an image in vs forms 
Csharp :: project programing languages in codecademy 
Html :: html yen symbol 
Html :: td align top 
Html :: html input regex only numbers 
Html :: how to embed my website into Discord 
Html :: email anchor tag 
Html :: feather icon cdn 
Html :: button open link in new tab 
Html :: how to center link in html 
Html :: bootstrap side by side columns 
Html :: tag input type float number html 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =