Search code examples
swiftsprite-kitgamekit

Create an obstacle with GKPolygonObstacle


I'm trying to manually create an obstacle like so:

let points = [vector_float2(-25, 50), vector_float2(25, 50), vector_float2(25, -50), vector_float2(-25, -50)]

let obs = GKPolygonObstacle(points: points, count: points.count)

However I get the following error:

Cannot convert value of type '[vector_float2]' to expected argument type
'UnsafeMutablePointer<vector_float2>' (aka 'UnsafeMutablePointer<float2>')

I'm not sure how to convert a vector_float2 array to an UnsafeMutablePointer

I've Googled but found no results, and looked through Apple's projects but couldn't seem to find what I was looking for.


Solution

  • I found my error -- I needed to do this:

    let pts = [vector_float2(0, 5), vector_float2(10, 10)] //just float2 also works I think

    let obstacle = GKPolygonObstacle(UnsafeMutablePointer(pts), count: pts.count)