1
votes

I'm developing an iOS game with cocos2D. My game is simple, there are levels, and a rotating sprite. The sprite need to go from the beginning to the end of the level without losing his lives.

So there is two possibilities for me :

1°) Already working good

  • Tilemap based levels with 2D pixels styles tilesets
  • Custom collision detection on the edge of the hero's sprite bounding box, and the tilemap collision.

2°) Would be better graphics, and better users experience (without physics, only collision):

  • map base on vector graphics / SVG
  • collision detection using the edge of the hero's sprite shape and the map

But, i read the cocos2D/Box2D documentation, and i doesn't found a collision detection on the edge of the sprite's shape ONLY. It's like a pixel perfect collision (already found algo).

I only want to know if one of the 4 edge of my hero's shape is colliding a border of the level, and if yes which shape is colliding (because my sprite is rotating).

Someone have an idea ?

Thank you a lot for your time.

2

2 Answers

2
votes

One polygon shape should be attached to your Hero's body via fixture. To detect a collision point use contacts between dynamic(hero) and static(walls) bodies.

0
votes

Just take your hero's shape and divide in half to find the pixel width of the hero shape (the radius) and detect collision if the distance between your hero and another sprite is equal to or less than this radius.