【问题标题】:libGDX getColor() methodlibGDX getColor() 方法
【发布时间】:2015-02-26 21:33:57
【问题描述】:

我有一个按钮网格,显示在舞台上。设置和获取按钮颜色的行为很奇怪。

int X=0;
int Y=0;
buttons[X][Y].setColor(Color.BLUE);  //this works, the button displays blue
boolean test = (buttons[X][Y].getColor()==Color.BLUE);
System.out.println(test);  //prints 'false' , why???
System.out.println(buttons[X][Y].getColor()); //prints '0000ffff'
System.out.println(Color.BLUE); //prints '0000ffff'

我需要能够为我正在创建的游戏设置和获取按钮的颜色。有谁知道发生了什么以及我能做什么?

【问题讨论】:

  • 您在比较引用而不是值。你可以改用boolean test = buttons[X][Y].getColor.equals(Color.BLUE);
  • 谢谢 Xoppa!我非常感谢您的有益和积极的回答。
  • buttons[X][Y].getColor().equals(Color.BLUE) - 这是真正有效的。谢谢。

标签: button libgdx


【解决方案1】:

Color 对象不同,但它们具有相同的值。因此,对象可能不等于==,但会等于.equal()。见What is the difference between == vs equals() in Java?

【讨论】:

    猜你喜欢
    • 2012-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多