AJPatel
AJPatel

Reputation: 2291

CCSprite in Cocos2d

I m begginer in cocos2d

I want to make simple game in cocos2d.

I use CCsprite for the image file but I want put some random shape like diamond....which is not image...i make this shape but when i use collision detection with other CCsprite then problem occur....then i make object of diamond..

how can i collision with diamond object....or how can i use this object in CCSprite....

Please give me proper answer...

Thanks in advance...

Upvotes: 0

Views: 769

Answers (2)

Lukman
Lukman

Reputation: 19164

Simple collision detection in Cocos2d is either overlapping-rectangles detection or point-in-rectangle detection. To detect collisions of complex shapes, you need to use physics engine (Box2D or Chipmunk) but that will certainly make your game not simple anymore :).

Or maybe you can use a two-passes collision detection. First you detect if the shapes' bounding rectangles overlap, and if they do then you use some math formula or something to check for the diamond shapes collision. Some skeleton code:

if (CGRectContainsRect([sprite1 boundingBox], [sprite2 boundingBox])) {
   /* the rectangles overlap so now use some trigonometric formula, 
      euler formula, harmonic series or fourier transform or something, 
      to further check if the actual shapes overlap or not :P */

}

Upvotes: 0

gixdev
gixdev

Reputation: 570

Just use this following method:
bool CGRectContainsRect ( CGRect rect1, CGRect rect2 );
To know more about, follow to https://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CGGeometry/Reference/reference.html

Upvotes: 1

Related Questions