gpt4 book ai didi

java - Blackberry Touch 事件检测触摸位置上的对象

转载 作者:行者123 更新时间:2023-12-01 15:52:36 25 4
gpt4 key购买 nike

这是我的第一个黑莓应用程序,我正在尝试为触摸屏设备制作一个简单的游戏。这是典型的图像分割成图 block 的情况,您必须将它们打乱,以便图 block 处于正确的顺序并显示图片。其目的是,用户将能够将图 block “拖动”到屏幕上他们想要的任何位置,并且他们将与将其放在上面的图 block 交换位置。

我正在为我的图 block 使用位图按钮

    HorizontalFieldManager hfm = new HorizontalFieldManager();
add(hfm);
hfm.add(button1);
hfm.add(button2);
etc...

我有一个名为 Puzzle screen 的类,如下所示:

class PuzzleScreen extends MainScreen implements FieldChangeListener {

我添加了以下内容来尝试检测屏幕上触摸的人的移动

protected boolean touchEvent(TouchEvent event) { 
case TouchEvent.MOVE:

PuzzleTile fieldMove = (PuzzleTile) this.getLeafFieldWithFocus();

// Dialog.alert("MOVE");

int[] x_points;
int[] y_points;
int[] time_points;
int size = event.getMovePointsSize();
x_points = new int[size];
y_points = new int[size];
time_points = new int[size];
event.getMovePoints(1, x_points, y_points, time_points);
return true;
}

return false;
}

我需要找到哪个图像图 block (位图按钮)位于 upevent 的位置。我有上面的坐标(我认为),但不确定如何找到与之相关的图 block 。

贝克斯

最佳答案

类似这样的事情。

static class TestScreen extends MainScreen  {

private static String down;

public TestScreen () {
HorizontalFieldManager hfm = new HorizontalFieldManager();
add(hfm);
hfm.add(new TestButton("bt1"));
hfm.add(new TestButton("bt2"));
hfm.add(new TestButton("bt3"));
hfm.add(new TestButton("bt4"));
hfm.add(new TestButton("bt5"));
hfm.add(new TestButton("bt6"));
}

public static void touchDown(TestButton tb) {
down = tb.getText();
System.out.println("DOWN in " + tb.getText());
}

public static void touchUp(TestButton tb) {
System.out.println("UP in " + tb.getText());
if(!down.equals(tb.getText()))
System.out.println("swap " + down + " and " + tb.getText());
down = "";
}




class TestButton extends LabelField {

public TestButton (String label) {
super(label);
}

protected boolean touchEvent(TouchEvent event) {
if(event.getEvent() == TouchEvent.UP)
TestScreen.touchUp(this);
else if(event.getEvent() == TouchEvent.DOWN)
TestScreen.touchDown(this);
return super.touchEvent(event);
}


}

}

关于java - Blackberry Touch 事件检测触摸位置上的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5713988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com