2012-01-28 20 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

ありがとう - 他のすべてのオブジェクトとの衝突をチェックするよりも効率的な方法がある場合は、そのようなループを作成しました。 – piotrpo

関連する問題