1

I am making a game using the accelerometer, basically my character is at the bottom of the screen and he needs to avoid objects falling from the top of the screen. I am using CGRectIntersectsRect to see if my character sprite has intersects my enemy sprite, but the problem with this is CGRectIntersectsRect detects the transparent sections of my character sprite.

Is there a way to make it ignore the transparency of the sprite?

akjoshi
  • 14,589
  • 13
  • 94
  • 116
Aaron
  • 41
  • 5

3 Answers3

0

One way is to use Box2d. Even if you don't want the physics simulation you can set up body shapes to be used for collision detection.

Alternatively, if you don't want to use C++, then Chipmunk also has shapes with collision detection. This post outlines some details: Chipmunk collision detection

Community
  • 1
  • 1
Jasper Blues
  • 26,772
  • 18
  • 95
  • 169
0

If you don't want to use a physics simulator, you can just think your sprites as multiple rectangles, so you test the hit for all the parts and not the whole bounding box. This may be easier and give you a good result if the sprite shape is simple.

Ricard Pérez del Campo
  • 2,307
  • 1
  • 17
  • 22
0

Besides physics engines with manually designed shapes (recommended for best performance) you can also use pixel-perfect collision detection if you need very accurate collision detection.

LearnCocos2D
  • 63,754
  • 20
  • 125
  • 213