I have set up a grid of 10x10 blocks to rise to different heights depending on integer values from an array, ranging from 0 to 6, where the code would multiply the integer by 50 and raise the block by that many units. It is working well so far, however I have found that inputting the numbers manually in a 100-entry array for each level is very tedious.
I’m certain there is a way to use a 10x10 image to input the values into the array, each number represented by a pixel’s color or a shade between white and black. I haven’t found a way to do so on my own, nor have I found any tutorials or questions that may help me find a way. Has anyone come across a way to use images for inputting information other than for textures?
You can bake your array from an image (but only within the editor) by using this code
UTexture2D* SourceTexture = ...some texture...
check(SourceTexture);
FTextureSource& SourceData = SourceTexture->Source;
if (SourceData.GetFormat() == TSF_BGRA8) // you can also parse other formats if you need
{
uint32 BytesPerPixel = SourceData.GetBytesPerPixel();
uint32 RowStride = SourceData.GetSizeX();
uint8* ImageData = SourceData.LockMip(0);
for ( ...walk thru X and Y as you want... )
{
uint8* PixelData = ImageData + (X + Y * RowStride) * BytesPerPixel;
...do something with given pixel data...
uint8 B = PixelData[0];
uint8 G = PixelData[0];
uint8 R = PixelData[0];
uint8 A = PixelData[0];
}
SourceData.UnlockMip(0);
}
In a packaged game SourceTexture->Source field might be ommited or empty.