2015-08-29 19 views
-1

我想用使用self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopF​​romPath:

self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromPath:(CGPathRef)]; 
在spriteKit

,但我不知道如何去做。我GOOGLE瞭如何創建路徑,但無法找到多少然後,當我做了一個UIBezier路徑,我不知道如何將其更改爲一個CGPath,然後在大約使用。我想用這些點來創建一條路徑(91,6),(184,222),(2,222),然後返回(91,6)做一個三角形。有人能幫我嗎。

回答

0

下面是使用路徑創建一個物理體的例子:

CGMutablePathRef trianglePath = CGPathCreateMutable(); 
CGPathMoveToPoint(trianglePath, nil, 91, 6); 
CGPathAddLineToPoint(trianglePath, nil, 184, 222); 
CGPathAddLineToPoint(trianglePath, nil, 2, 222); 
CGPathAddLineToPoint(trianglePath, nil, 91, 6); 

myNode.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:trianglePath]; 
// set rest of properties... 

CGPathRelease(trianglePath); 
+1

完美正是我想要的THX – user1114881