Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法以编程方式不断地改变背景的颜色/颜色,例如,我希望开始的颜色是完美的蓝色(例如),然后每次Update()调用我都希望背景慢慢变成绿色,然后是黄色,然后是蓝色等......我希望颜色淡入下一个颜色,而不是突然切换。
Update()
有什么想法可以实现这一目标吗?我知道有,GraphicsDevice.Clear(Color.CornflowerBlue);但这显然不是我想要的。
GraphicsDevice.Clear(Color.CornflowerBlue);
@BrianRasmussen 是完全正确的。您可以改变每一帧的清晰颜色。使用Color采用数字值而不是颜色枚举值的构造函数之一。
Color
这个,
GraphicsDevice.Clear(new Color(byte r, byte g, byte b));
或者这个
GraphicsDevice.Clear(new Color(float r, float g, float b, float a));
并且每一帧,更新您的r、g和的值b。简单的。
r
g
b
GraphicsDevice.Clear正是你想要的。
GraphicsDevice.Clear
您仍然需要一种在颜色之间进行插值的方法:
var red = Color.Red; var green = Color.Green; // Gives you a color at half the distance between red and green var color = Color.Lerp(red, green, 0.5f);
如果您想浏览整个调色板,您可以将颜色转换为HSL 或 HSV并对色调进行动画处理。