Question

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?

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top