سؤال

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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top