You should create SKSpriteNode
as you did in the question and just attach physic body to it with triangle shape:
var trianglePath = CGPathCreateMutable()
CGPathMoveToPoint(trianglePath, nil, -TopTriangel.size.width/2, -TopTriangel.size.height/2)
CGPathAddLineToPoint(trianglePath, nil, TopTriangel.size.width/2, -TopTriangel.size.height/2)
CGPathAddLineToPoint(trianglePath, nil, 0, TopTriangel.size.height/2)
CGPathAddLineToPoint(trianglePath, nil, -TopTriangel.size.width/2, -TopTriangel.size.height/2)
TopTriangel.physicsBody = SKPhysicsBody(polygonFromPath: trianglePath)
You can add this line:
sceneView.showsPhysics = true
to make sure the shape match your image (SKSpriteNode
), just remember to remove it after debugging.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…