frankibanki
frankibanki

Reputation: 115

Swift SpriteKit creating mutable path (CGMutablePathRef)

I found this code on stack overflow.

CGMutablePathRef path = CGPathCreateMutable()
CGPathMoveToPoint(path, nil, 0, -(self.tileSize.height / 2))
CGPathAddLineToPoint(path, nil, (self.tileSize.width / 2), 0)
CGPathAddLineToPoint(path, nil, 0, (self.tileSize.height / 2))
CGPathAddLineToPoint(path, nil, -(self.tileSize.width / 2), 0)
CGPathCloseSubpath(path)

its a part of an answer and the code should create a path that have the shape of an isometric tile but its not working. So somebody knows why and how to create this mutablePath? Thank you.

Upvotes: 0

Views: 491

Answers (1)

Luca Angeletti
Luca Angeletti

Reputation: 59536

If your problem is that the code does not compile, you just need to convert it from Objective-C to Swift

let path = CGPathCreateMutable()
CGPathMoveToPoint(path, nil, 0, -(self.tileSize.height / 2))
CGPathAddLineToPoint(path, nil, (self.tileSize.width / 2), 0)
CGPathAddLineToPoint(path, nil, 0, (self.tileSize.height / 2))
CGPathAddLineToPoint(path, nil, -(self.tileSize.width / 2), 0)
CGPathCloseSubpath(path)

Upvotes: 1

Related Questions