这是我的第一个黑莓应用程序,我正在尝试为触摸屏设备制作一个简单的游戏。这是典型的图像分割成的图块,你必须对它们进行解读,这样图块才能按正确的顺序显示出来。其目的是用户将能够“拖动”一个磁贴在屏幕上的任何地方,他们将与他们放在上面的磁贴交换位置。
我正在对我的磁贴使用位图按钮
HorizontalFieldManager hfm = new HorizontalFieldManager();
add(hfm);
hfm.add(button1);
hfm.add(button2);
etc...我有一个名为Puzzle的类,如下所示:
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;
}我需要找出哪个图像瓦片(bitmapbutton)在upevent的位置。我有(我认为)上面的坐标,但不确定如何找到与哪个瓷砖相关。
Bex
发布于 2011-04-19 19:32:00
就像这样。
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);
}
}
} https://stackoverflow.com/questions/5713988
复制相似问题