I am developing a 2D game in C#/XNA where the sprites/backgrounds/etc are Texture2Ds. I am interested in rendering a particular scene in either "daytime" or "nighttime". Obviously one option would be to have two copies of every image, one darker than the other, but this isn't very scalable. Is there a way to adjust the colours on the fly so that they appear darker? I'd guess it would be easiest to adjust the brightness or something (or whichever would look best) than trying to apply some sort of uniform transform to RGB values, but that's a lesser issue 开发者_运维百科at the moment. Is there any way to say "draw this Texture2D, but adjust all colours in this way by this amount"?
Thanks!
Check the overloads of SpriteBatch.Draw that accept a color parameter. It does exactly what you are looking for.
in your share e.g.
ps_out ps( ps_in In )
{
PS_OUT Out = ( PS_OUT ) 0;
float4 color;
color = tex2D( sBase, In.Base.xy );
Out.Color = color;
return Out;
}
you could use alpha blending and then use the swizzle operator on the color member and multiply the alpha/opacity of the color.
e.g. color.a = color.a * opacity / 255.0f
精彩评论