2015-06-12 42 views
0

我有一個精靈,當達到一定位置時,它被刪除:保存雪碧位置

if(sprite.getY()>=700){ 
     enemyIterator.remove(); 
     Pools.free(sprite); 
} 

我wan't它被刪除之前保存精靈的最後一個位置,我想sprite.getX()sprite.getY()但那些只有在精靈在遊戲中時纔可用。

+0

你是否保留刪除引用後的精靈?你什麼時候需要使用這些職位?移除後或稍後的某個時間點? – plastique

+0

難道你不能在你的'enemyIterator.remove();'行之前保存它嗎? – Tenfour04

+0

@plastique我將在他們被移除後使用他們的位置。 –

回答

1

根據提供的附加信息。 Sprite方法getX()getY()返回浮點值。因此,您可以將這些方法返回的值分配給float類型的變量供以後使用。

float lastX, lastY; 

if(sprite.getY()>=700){ 
    lastX = sprite.getX(); 
    lastY = sprite.getY(); 
    enemyIterator.remove(); 
    Pools.free(sprite); 
} 

System.out.println("Removed sprite coordinates where: " + lastX + ", " + lastY); 
0

也許你不能得到最後的位置,精靈是的,但你可以節省你在這個框架繪製的最後一個位置,你總是需要設置的位置,當你繪製每一幀,如果事情發生,抓例如,最後一個位置。

private Rectangle bordes; 

public Ball(float x, float y,int isMoved) { 
    .......... 
     texture = new Texture(Gdx.files.internal("bola.png")); 
     bordes = new Rectangle(x, y, texture.getWidth(), texture.getHeight()); 
    .......... 
    } 

public void draw(SpriteBatch batch) { 
    //where i draw my last texture or sprite was bordes.x bordes.y in this frame 
     batch.draw(texture, bordes.x, bordes.y, texture.getWidth(), texture.getHeight()); 
    } 

public vois getLastPosition(){ 

lastX = bordes.x; 
lastY = bordes.y; 

}