Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How to achieve (almost) perfect/exact collision detection between two CCSprite's?

$
0
0

Hello guys,

i am trying to detect collision of two CCSprite's, a ball (PlayFigureSprite) and something that boosts that ball in a specific direction (BoostSprite):

[Insert picture here showing two BoostSprite's and one PlayFigureSprite with their collision boundingboxes.
One BoostSprite (right one) is rotated to the bottom right and it's boundingbox is bigger than itself.
Left BoostSprite has a boundingbox that perfectly fits it size because it's not rotated.
Backgroundcolor of picture is blue.]

Sadly i cant add a picture because of this message: "You have to be around for a little while longer before you can post links."

For debugging reasons i used CCDrawNode to show the BoundingBoxTransformedToParent of the PlayFigureSprite and BoostSprite's objects.
To detect the collision i use following code:

boostSpriteObj.BoundingBoxTransformedToParent.IntersectsRect(playFigureSpriteObj.BoundingBoxTransformedToParent);

Everything works fine. The only problem is the collision detection when the BoostSprite is rotated.
Rotated BoostSprite's have a bigger BoundingBoxTransformedToParent than their actual size because the BoundingBoxTransformedToParent is not rotated when the sprite was rotated.

In the picture above the ball would be accelerated to the bottom right if it hits the blue area next to the BoostSprite (right one) which is unwanted behaviour. The ball should only be affected by the boost if it really hits the drawn BoostSprite. For the left BoostSprite it works perfect.

I couldn't find a way to rotate that boundingbox or create a boundingpolygon around CCSprite's for better approximation (could also be useful for round objects like the ball).

My Question:
How can I create an almost exact collision detection between two CCSprite's (return only true if the considered CCSprite's REALLY overlap/collide) ?


Viewing all articles
Browse latest Browse all 204402

Trending Articles