私は境界ボックスを使用して衝突をチェックします。タッチには問題ありませんが、2 つのスプライトの衝突にはまったく問題ありません (それらはすべて円形ですが、バウンディング ボックスは長方形です)。
より良い方法はありますか?(以下のコードを変更していただければ幸いです:
-(bool) isFishCollidingWithRect:(CGRect) rect
{
FishEntity* fish;
CCARRAY_FOREACH(fishes, fish)
{
if (fish.visible && CGRectIntersectsRect([fish boundingBox], rect)) {
[fish gotHit];
return YES;
}
}
return NO;
}
元の四角形と頂点が円にちょうど接する四角形の中間にある、より小さな四角形を取得する良い方法があると思います。サイズは簡単に取得できますが、四角形が回転する可能性があるため、座標は非常に難しく、私の数学は最悪です
-(bool) isBirdCollidingWithSprite:(CCSprite*) sprite
{
BirdEntity* bird;
CCARRAY_FOREACH(birdsAlone, bird)
{
float distance = sqrt((bird.anchorPoint.x - sprite.anchorPoint.x) * (bird.anchorPoint.x - sprite.anchorPoint.x) + (bird.anchorPoint.y - sprite.anchorPoint.y) * (bird.anchorPoint.y - sprite.anchorPoint.y));
if (bird.visible && (bird.contentSize.width / 2 + sprite.contentSize.width / 2) >= distance) {
if ([bird inBubble] == NO) {
[bird bubbled];
}
return YES;
}
}
return NO;
}
まあ、魚は常にヒットします。 contentSize はバッチノードのテクスチャ全体であると思います。何を使えばいいですか?