ANDROID ANDENGINE - 拖放堆叠精灵 [英] ANDROID ANDENGINE -- drag and drop stacked sprites
问题描述
在我的应用我有一些精灵,我需要拖放上的显示。
我定义了BitmapTextureAtlas和相应的TextureRegion,然后i'have创建从这些数据可拖动的Sprite。
一些精灵必须在相同的位置被设置,它们必须被层叠
一切正常,只是要叠精灵接缝但是当我触摸的拖曳距之一,而不是拖动第一个在上面,这让我拖走总是第一个底部。
如何解决呢?
此功能inizializes精灵
公共矢量<&雪碧GT; initSprite(矢量<&TextureRegion GT; tRegionV){
矢量<&雪碧GT; AUX =新的矢量<&雪碧GT;();
的for(int i = 0; I< dataV.size();我++){
最终诠释差距= dataV.elementAt(我).gap;
雪碧=新的Sprite(dataV.elementAt(我).X,dataV.elementAt(I).Y,tRegionV.elementAt(I)) // GESTIONE德尔拖放放大器;下降
{
@覆盖
公共布尔onAreaTouched(最终的TouchEvent pSceneTouchEvent,
最终浮动pTouchAreaLocalX,最终浮动pTouchAreaLocalY){
的setPosition(pSceneTouchEvent.getX() - this.getWidth()/ 2,pSceneTouchEvent.getY()
- 间隙/*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()); 返回true;
}
}; 如果(精灵== NULL)的System.out.println(AAAAAA精灵+ I +空);
aux.addElement(精灵);
} 返回辅助;
}
和我这种方式设置精灵在场景
的for(int x = 0; X< spriteV.size(); X ++){
scene.getLastChild()attachChild(spriteV.elementAt(X))。
}
请参阅:<一href=\"http://$c$c.google.com/p/andengineexamples/source/browse/src/org/anddev/andengine/examples/MultiTouchExample.java\"相对=nofollow> MultiTouchExample.java
您可能想要做:
this.mScene.setOnAreaTouchTraversalFrontToBack();
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));
}
You probably want to do:
this.mScene.setOnAreaTouchTraversalFrontToBack();
这篇关于ANDROID ANDENGINE - 拖放堆叠精灵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!