简体   繁体   English

无法比较两种SFML颜色

[英]Cannot compare two SFML Colors

I have to compare two colors in SFML.net. 我必须在SFML.net中比较两种颜色。 In C++ it's possible because there is defined == operator. 在C ++中,可能是因为定义了==运算符。 In SFML.net Visual Studio won't let me compile the code. 在SFML.net中,Visual Studio不允许我编译代码。 How to resolve that? 如何解决? Error: 1>E:\\DB\\Dropbox\\Repozytoria\\ARDSQL GUI\\Sources\\StatusBar.cs(91,17,91,70): error CS0019: Operator '==' cannot be applied to operands of type 'SFML.Graphics.Color' and 'SFML.Graphics.Color' 错误: 1>E:\\DB\\Dropbox\\Repozytoria\\ARDSQL GUI\\Sources\\StatusBar.cs(91,17,91,70): error CS0019: Operator '==' cannot be applied to operands of type 'SFML.Graphics.Color' and 'SFML.Graphics.Color'

My code: 我的代码:

if (base.barRectangle.FillColor == Color.Green)
{
     ///Do something...
}

Try comparing the individual components: 尝试比较各个组件:

if (base.barRectangle.FillColor.r == Color.Green.r &&
    base.barRectangle.FillColor.g == Color.Green.g &&
    base.barRectangle.FillColor.b == Color.Green.b){
     ///Do something...
}

Or you could try writing a color comparison function of your own: 或者,您可以尝试编写自己的颜色比较功能:

bool isEqualSFColors(SFML.Graphics.Color c1, SFML.Graphics.Color c2){
    if (c1.r == c2.r &&
        c1.g == c2.g &&
        c1.b == c2.b){
        return true;
    }
    return false;
}

Note that I did not include alpha into the comparison (yourColor.a is how you would get it). 请注意,我没有在比较中包括alpha(yourColor.a是您将如何获得的)。

SFML is also open source, so you are free to add the operator overloading you desire: http://msdn.microsoft.com/en-us/library/aa288467(v=vs.71).aspx SFML也是开源的,因此您可以自由添加所需的运算符,以使其过载: http : //msdn.microsoft.com/zh-cn/library/aa288467( v=vs.71) .aspx

It's also possible that you are using an older version/binary that you found. 您可能还会使用发现的旧版本/二进制文件。 I haven't used SFML.net, but I'm sure if you grab a newer copy there may already be this feature built-in. 我还没有使用过SFML.net,但是我敢肯定,如果您获取较新的副本,可能已经内置了此功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM