2012-01-28 38 views

回答

2

當你創建一個新的精靈,用戶數據添加到它:

sprite.setUserData("sprite"); 

然後,您創建了一個定位精靈後,您將其添加遍歷現有的精靈前:

int count = scene.getChildCount(); 
for(int i = 0; i < count; i++) { 
    IEntity entity = scene.getChild(i); 
    if(entity instanceof Sprite) { 
     if(entity.getUserData().equals("sprite")) 
      if(((Sprite)entity).collidesWith(newSprite)) 
       //Don't add the new sprite. 
} 

用戶數據可以是任何你想要的,它不一定是一個字符串。

+0

謝謝 - 我做了這樣的循環,只是工作,如果有比檢查所有其他對象的collisision更有效的方法。 – piotrpo 2012-01-29 14:30:32