libGDX:使用touchDragged从Actor绘制和删除颜色 [英] libGDX : Paint And Remove Color From Actor with touchDragged
问题描述
我创建了 Button
actor的二维数组,然后添加了 new ClickListener(){touchDragged}
作为以下代码:
I created two-dimensional array of Button
actor, then I added new ClickListener() {
touchDragged }
as the following code:
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
(它工作正常),如图
the code inside touchDragged
method if the buttons isOver
the buttons colored GREEN
(it works fine) as shown in image
现在,我如何从同一调用 touchDragged
方法中的按钮中删除 Color.GREEN
即 (Color.WHITE
),我的意思是如果 isOver()
仍然 true
??
Now, How can I remove Color.GREEN
i.e. (Color.WHITE
) from buttons in the same calling touchDragged
method, I mean undo GREEN
to WHITE
if the isOver()
still true
??
此图片清除了我的问题:
this image clear my question :
就像国王公司的字母游戏一样,如果您知道的话:).
like Alphabetty Game from king company, if you know it :).
对不起,英语不好
推荐答案
1-创建 List
:
private List<Integer> list;
// In create OR show Method
list = new ArrayList<Integer>();
2-创建此行代码(作为 buttons [row] [col]
的ID):
2- Create this line code (as ID for buttons[row][col]
):
buttons[row][col].setName("" + id++);
3-循环后,在您的 touchDragged
..中编写以下代码:
3- Write this code inside your touchDragged
.. after your loop:
if (buttons[row][col].isOver()) {
try {
if (list.contains(Integer.parseInt(buttons[row][col].getName()))) {
if(Integer.parseInt(buttons[row][col].getName()) == list.get(list.size() - 2)) {
stage.getRoot().findActor("" + list.get(list.size() - 1)).setColor(Color.WHITE);
list.remove(list.size() - 1);
}
} else {
buttons[row][col].setColor(Color.GREEN);
list.add(Integer.parseInt(buttons[row][col].getName()));
}
} catch (Exception e) {
System.out.println(e.getClass());
}
}
4-在此视频
这篇关于libGDX:使用touchDragged从Actor绘制和删除颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!