Question

When rehearsing Cocos2d V3 physics with debug mode enabled I noticed that physics body attached to its sprite has different anchor point from that of the sprite itself. Here's how it looks:

enter image description here

And this is how I create a sprite with physics body:

CCSprite *beam=[CCSprite spriteWithSpriteFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"w272.png"]];
beam.physicsBody=[CCPhysicsBody bodyWithRect:beam.boundingBox cornerRadius:0];
beam.position=ccp(125, 160);
[physicsWorld addChild:beam];

Do you have any idea how to fix this? I don't set any anchor point anywhere.

Was it helpful?

Solution

Physics objects automatically calculate a center of gravity, which is slightly different than an anchor point. Your real problem though is that you are using the sprite's bounding box as the rectangle to create the body and that's expressed in local coordinates. You want to make a text that goes from (0,0) to content size.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top