2016-03-11 48 views
0

我不得不采取以下代码来为我的敌人定制physicsBody。 看到下面的代码:SKPhysicsbody error on collision swift

let offsetX = CGFloat(Enemy.frame.size.width * Enemy.anchorPoint.x) 
let offsetY = CGFloat(Enemy.frame.size.height * Enemy.anchorPoint.y) 

let path = CGPathCreateMutable() 

CGPathMoveToPoint(path, nil, 25 - offsetX, 73 - offsetY) 
CGPathAddLineToPoint(path, nil, 32 - offsetX, 72 - offsetY) 
CGPathAddLineToPoint(path, nil, 45 - offsetX, 66 - offsetY) 
CGPathAddLineToPoint(path, nil, 47 - offsetX, 63 - offsetY) 
CGPathAddLineToPoint(path, nil, 43 - offsetX, 11 - offsetY) 
CGPathAddLineToPoint(path, nil, 25 - offsetX, 2 - offsetY) 
CGPathAddLineToPoint(path, nil, 11 - offsetX, 15 - offsetY) 
CGPathAddLineToPoint(path, nil, 5 - offsetX, 29 - offsetY) 
CGPathAddLineToPoint(path, nil, 5 - offsetX, 30 - offsetY) 
CGPathAddLineToPoint(path, nil, 3 - offsetX, 44 - offsetY) 
CGPathAddLineToPoint(path, nil, 3 - offsetX, 51 - offsetY) 
CGPathAddLineToPoint(path, nil, 7 - offsetX, 65 - offsetY) 
CGPathAddLineToPoint(path, nil, 9 - offsetX, 67 - offsetY) 
CGPathAddLineToPoint(path, nil, 15 - offsetX, 70 - offsetY) 

CGPathCloseSubpath(path) 

Enemy.physicsBody = SKPhysicsBody(polygonFromPath: path) 

当我运行这段代码我physicsBody是我的照片尺寸的一半。并坐在图片的左下角。我该如何解决?

回答

0

我想通了,如果你乘以它应该工作的所有值! 请参阅下一行代码:

CGPathAddLineToPoint(path, nil, 11*2 - offsetX, 15*2 - offsetY)