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

发布于 2024-11-02 15:38:04 字数 1174 浏览 1 评论 0原文

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

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

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

我有一个名为“拼图屏幕”的类,如下所示:

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;
    }

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

贝克斯

This is my first blackberry app and I am attempting to make a simple game for a touch screen device.
Its the typical image split into tiles and you have to unscramble them so the tiles are in the correct order and show the picture.
The intention is that the user will be able to "drag" a tile anywhere they want on the screen and they will swap places with the tile they drop it over.

I am using bitmapbuttons for my tiles

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

I have a class called Puzzle screen as follows:

class PuzzleScreen extends MainScreen implements FieldChangeListener {

I have added the following to try and detect the movement of the persons touch on the screen

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;
    }

I need to find which image tile (bitmapbutton) is at the position of the upevent.
I have the coordinates (I think) above but not sure how to find which tile that relates to.

Bex

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回忆凄美了谁 2024-11-09 15:38:04

像这样的东西。

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);
    }


}

} 

Something like this.

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);
    }


}

} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文