Reputation: 849
I have 2 images without background with triangles, I want connect one triangle with another, but Sprite kit thinking that my images is square not a triangle, and call me didBeginContact not in right time, for example:
I create my sprite like this:
self.sprite = [SKSpriteNode spriteNodeWithImageNamed:spriteName];
[self.sprite setSize:CGSizeMake(40, 40)];
self.sprite.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.sprite.size];
self.sprite.physicsBody.mass = 0;
self.sprite.physicsBody.usesPreciseCollisionDetection = YES;
self.sprite.physicsBody.categoryBitMask = Category;
self.sprite.physicsBody.collisionBitMask = 0;
self.sprite.physicsBody.contactTestBitMask = Category;
self.sprite.physicsBody.dynamic = YES;
Upvotes: 0
Views: 274
Reputation: 20284
Contacts between two bodies depend upon their physicsBody, not their texture. So, when you use
self.sprite.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.sprite.size];
You are attaching a rectangular physicsBody.
You need to create a triangular physicsBody using the method:
[SKPhysicsBody bodyWithPolygonFromPath:path];
Read up on the method here.
In order to get the values for creating a path, you can use the SKPhysicsBody Path Generator tool.
Upvotes: 2