smarts1l
Trying to convert TMX loading Python Code into C#
How would i translate this:
tmx_data = load_pygame('../data/map.tmx')
for layer in ['HouseFloor', 'HouseFurnitureBottom']:
for x, y, surf in tmx_data.get_layer_by_name(layer).tiles():
Generic((x * TILESIZE,y * TILESIZE), surf, self.all_sprites, LAYERS['house bottom'])
into C#? I am using Raylib as the texture controller and the group is a list called SpritesList and the Texture is just called SpriteImage.
5 replies
Error with getting pixels
I have tried to create some code to get the pixels of an uploaded image but the function doesn't seem to work correctly. It gives extremely strange outputs so it isn't that the r,g,b values are looking at the wrong index in the array. It does work for black and white but no colours. Does anyone know why?
This is the part of my code where the error occurs
var pixelData = createBytes(width, height);
string oldr = "0", oldb = "0", oldg = "0";
string[] compressed = new string[height * width];
int godown = 0;
var path = op.FileName;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int index = y * (width*4) + 4 * x; byte blue = pixelData[index]; byte green = pixelData[index + 1]; byte red = pixelData[index + 2]; int arraySlot = x +(y*width);int StandardArraySlot = arraySlot - godown; string r = red.ToString("D3"); string g = green.ToString("D3"); string b = blue.ToString("D3"); MessageBox.Show(r+" "+g+" "+b); public byte[] createBytes(int width,int height) { int stride = width * 4; byte[] pixelData = new byte[height * stride]; image.CopyPixels(new Int32Rect(0, 0, width, height), pixelData, stride, 0); return pixelData;
}
int index = y * (width*4) + 4 * x; byte blue = pixelData[index]; byte green = pixelData[index + 1]; byte red = pixelData[index + 2]; int arraySlot = x +(y*width);int StandardArraySlot = arraySlot - godown; string r = red.ToString("D3"); string g = green.ToString("D3"); string b = blue.ToString("D3"); MessageBox.Show(r+" "+g+" "+b); public byte[] createBytes(int width,int height) { int stride = width * 4; byte[] pixelData = new byte[height * stride]; image.CopyPixels(new Int32Rect(0, 0, width, height), pixelData, stride, 0); return pixelData;
}
15 replies