문제

I am creating a custom edge path for a SKSpriteNode's physicsBody.

CGMutablePathRef edgePath = CGPathCreateMutable();

CGPathMoveToPoint(edgePath, NULL, -100, -70);
CGPathAddLineToPoint(edgePath, NULL, -100, 40);
CGPathAddLineToPoint(edgePath, NULL, -80, -20);
CGPathAddLineToPoint(edgePath, NULL, 30, -20);
CGPathAddLineToPoint(edgePath, NULL, 100, 100);
CGPathAddLineToPoint(edgePath, NULL, 100, -70);
CGPathCloseSubpath(edgePath);

I have tried to allocate the physicsBody using the following codes:

sprite.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromPath:edgePath];

sprite.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:edgePath];

sprite.physicsBody = [SKPhysicsBody bodyWithEdgeChainFromPath:edgePath];

None of these enable the sprite to be affected by Gravity.

However, if I use a simple bodyWithCircleOfRadius: the sprite gets affected by gravity.

Can anybody throw some light on why this happens?

도움이 되었습니까?

해결책

Edge loop and chain create static (immovable) bodies. They will not be affected by gravity.

Polygon shape bodies should be affected by gravity. However you must ensure the polygon has counter-clockwise winding, is not self-intersecting and its shape is convex. Otherwise the results are unpredictable.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top