Reputation: 29
I googled this for quite some time but only found responses on how to do this the other way, finding coordinates based on color.
This has been probably answered somewhere but it is buried below all of the other responses.
--
So, as a simple way of making a level editor for my game, i have the game load a texture, and then loop through the pixels it. Different colors in the texture equate to different objects.
Everything else is working fine, but i am unable to find how to get the color of the pixel in the given co-ordinates.
Upvotes: 0
Views: 46
Reputation: 9944
Basically what you need to do is to store you texture color informations into a one dimensional array using the Texture2D.GetData Method
var colorTable = new Color[texture.Width*texture.Height];
texture.GetData(colorTable);
then to access a specific pixel (let say X,Y) all what you need to do is to get its corresponding color from the array like so
var pixelColor=colorTable[texture.Width * Y + X];
Upvotes: 1