作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了 Button
actor 的二维数组,然后添加了 new ClickListener() {
如下代码:
touchDragged }
buttons = new Button[3][3];
for (int row = 0; row < buttons.length; row++) {
for (int col = 0; col < buttons[0].length; col++) {
buttons[row][col] = new Button(drawable);
buttons[row][col].addListener(new ClickListener() {
@Override
public void touchDragged(InputEvent event, float x, float y, int pointer) {
for (int row = 0; row < buttons.length; row++) {
for (int col = 0; col < buttons[0].length; col++) {
if (buttons[row][col].isOver()) {
buttons[row][col].setColor(Color.GREEN);
}
}
}
}
}
}
touchDragged
方法中的代码,如果按钮isOver
按钮颜色为GREEN
(它工作正常),如图所示
现在,如何从同一调用 touchDragged
方法中的按钮中删除 Color.GREEN
即 (Color.WHITE
),我的意思是如果 isOver()
仍然是 true
,则将 GREEN
撤消为 WHITE
??
就像 King 公司的 Alphabetty Game,如果你知道的话:)。
抱歉,英语不好
最佳答案
您可以使用 if 语句来检查方 block 的颜色。如果是白色,则将其涂成绿色,反之亦然。
我有类似的东西,由于某种原因,你不能直接比较 if 语句中的颜色,但是将它们更改为 rgb int 值可以解决这个问题。您可以从各种 RGB 选项中进行选择,例如 rgba8888 或 argb8888 等,选择一个适合您需求的选项。最简单的就是 rgb888。它是 color 类中的静态方法,传递给它一个颜色,它将返回一个 int。
if(Color.rgb888(button[row][col].getColor()) == Color.rgb888(Color.Green()))
{
button[row][col].setColor(Color.White());
}
关于java - libGDX : Paint And Remove Color From Actor with touchDragged,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32878595/
我是一名优秀的程序员,十分优秀!