为什么我的SKPhysicsBody定位在离它连接的SKSpriteNode很远的地方?这就是我创建物理体的方式:
self.pin = [SKSpriteNode spriteNodeWithImageNamed:[IPGameManager sharedGameData].world.player.ship.type];
self.pin.position = CGPointMake([IPGameManager sharedGameData].world.player.location.xCoordinate, [IPGameManager sharedGameData].world.player.location.yCoordinate);
self.pin.userInteractionEnabled = NO;
NSLog(@"Pin width: %f", self.pin.size.width);
NSLog(@"Pin position: %f %f", self.pin.position.x, self.pin.position.y);
self.pin.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:self.pin.size.width * 0.5 center:self.pin.position];
self.pin.physicsBody.dynamic = YES;
self.pin.physicsBody.allowsRotation = NO;
self.pin.physicsBody.friction = 0.0;
self.pin.physicsBody.linearDamping = 0.0;通过设置skView.showsPhysics = YES;,它显示了物理体,圆圈远离了SKSpriteNode。知道为什么吗?
发布于 2014-07-18 03:02:28
您正在将physicsBody的中心位置设置为self.pin的CGPoint值,该值是self.pin的父节点坐标空间中的一个点。如果您希望物理实体仅在中心居中,则可以使用0,0位置作为中心(或者根本不使用带中心的方法),或者如果移动了self.pin的锚点位置,则使用偏移点:
[SKPhysicsBody bodyWithCircleOfRadius:self.pin.size.width * 0.5 center:CGPointZero];
//OR
[SKPhysicsBody bodyWithCircleOfRadius:self.pin.size.width * 0.5 ]https://stackoverflow.com/questions/24809003
复制相似问题