ANDROID ANDENGINE——拖放堆叠的精灵

发布于 2024-12-13 23:15:28 字数 1540 浏览 4 评论 0原文

在我的应用程序中,我需要将一些精灵拖放到显示屏上。 我定义了BitmapTextureAtlas和相应的TextureRegion,然后我从这些数据创建了可拖动的精灵。

有些精灵必须设置在同一位置并且必须堆叠。

一切工作正常,除了精灵接缝要堆叠之外,但是当我触摸拖动一个精灵时,它不是拖动顶部的第一个,而是总是拖动底部的第一个。

我该如何修复它?

这个函数初始化精灵

public Vector<Sprite> initSprite(Vector<TextureRegion> tRegionV){
    Vector<Sprite> aux = new Vector<Sprite>();
    for(int i=0; i<dataV.size(); i++ ){
        final int gap = dataV.elementAt(i).gap;
        sprite = new Sprite(dataV.elementAt(i).x, dataV.elementAt(i).y, tRegionV.elementAt(i))

        // gestione del drag & drop
        {
            @Override
            public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,
                    final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
                setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2, pSceneTouchEvent.getY()
                        - gap /*this.getHeight() / 2*/);
                //System.out.println("POSIZIONE X: "+(pSceneTouchEvent.getX()- this.getWidth() / 2) +" --- Y: " +(pSceneTouchEvent.getY() - this.getHeight() / 2));
                //System.out.println("ALTEZZA: "+this.getHeight());

                return true;
            }
        };

        if(sprite==null)   System.out.println("AAAAAA sprite" +i+" null");
        aux.addElement(sprite);
    }

    return aux;
}

,我以这种方式在场景中设置精灵

    for(int x=0;x<spriteV.size();x++){
        scene.getLastChild().attachChild(spriteV.elementAt(x));
    }

in my app I have some sprites that i need to drag and drop over the display.
i defined the BitmapTextureAtlas and the corresponding TextureRegion, and then i'have created the draggable sprite from those data.

Some sprites must be set in the same position and they have to be stacked.

everything works fine except that the sprites seams to be stacked but when i touch an drag away one, instead of dragging the first on the top, it makes me drag away always the first on the bottom.

how can i fix it?

this function inizializes the sprite

public Vector<Sprite> initSprite(Vector<TextureRegion> tRegionV){
    Vector<Sprite> aux = new Vector<Sprite>();
    for(int i=0; i<dataV.size(); i++ ){
        final int gap = dataV.elementAt(i).gap;
        sprite = new Sprite(dataV.elementAt(i).x, dataV.elementAt(i).y, tRegionV.elementAt(i))

        // gestione del drag & drop
        {
            @Override
            public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,
                    final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
                setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2, pSceneTouchEvent.getY()
                        - gap /*this.getHeight() / 2*/);
                //System.out.println("POSIZIONE X: "+(pSceneTouchEvent.getX()- this.getWidth() / 2) +" --- Y: " +(pSceneTouchEvent.getY() - this.getHeight() / 2));
                //System.out.println("ALTEZZA: "+this.getHeight());

                return true;
            }
        };

        if(sprite==null)   System.out.println("AAAAAA sprite" +i+" null");
        aux.addElement(sprite);
    }

    return aux;
}

and i set the sprites in the scene this way

    for(int x=0;x<spriteV.size();x++){
        scene.getLastChild().attachChild(spriteV.elementAt(x));
    }

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

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

发布评论

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

评论(1

阿楠 2024-12-20 23:15:28

请参阅:MultiTouchExample.java

你可能想做:

this.mScene.setOnAreaTouchTraversalFrontToBack();

See: MultiTouchExample.java

You probably want to do:

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