ANDROID ANDENGINE——拖放堆叠的精灵
在我的应用程序中,我需要将一些精灵拖放到显示屏上。 我定义了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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅:MultiTouchExample.java
你可能想做:
See: MultiTouchExample.java
You probably want to do: