I have read somewhere that sprites can detect the background color, but I don't remember where and how it's working. What I'm trying to do is just a function to detect if the sprite is on a special surface, that has a special color, instead of using collision dedection between objects. Help is preciated! Thanks!
You can render your entire scene to a render target instead of directly to screen. A render target is also a texture and you can query the color of each pixel by getting the data from the texture. See this StackOverflow answer on how to get the color of a pixel in a texture.
- The color data is a 1 dimensional array so you need to do a tiny bit of math to go from 2D to 1D to get the correct pixel data.
- Getting the color data like this can be slow, but don't worry about it until you experience actual performance issues. If you only do this once per frame you should be alright.
You can find a tutorial for XNA here that uses a texture as a color key for collision detection. A lot of the techniques you need are explained there in detail so be sure to check it out!