问题
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));
}
回答1:
See: MultiTouchExample.java
You probably want to do:
this.mScene.setOnAreaTouchTraversalFrontToBack();
来源:https://stackoverflow.com/questions/8027400/android-andengine-drag-and-drop-stacked-sprites