ios - How to show GKPath in GameplayKit -
is there trick show gkpath?
for example path:
class scenariopath: gkpath { //set // | | | | | | // --a--b--c--d--e--f-- // | | | | | | //6 punti con raggio quasi 600 e lato 500 va bene per scenario 2k * 3k static let lato = float(500.0) static let maxy = float(0.0) static let radius : float = 600.0 static let maxynormalize = maxy - radius static let pts = [ vector_float2(-lato,maxynormalize), vector_float2(+lato,maxynormalize), vector_float2(-2*lato,maxynormalize), vector_float2(+2*lato,maxynormalize), vector_float2(-3*lato,maxynormalize), vector_float2(+3*lato,maxynormalize)] init () { super.init(points: unsafemutablepointer(scenariopath.pts), count: scenariopath.pts.count, radius: scenariopath.radius, cyclical: true) } }
i'm looking simple func show path. thanks
gameplaykit not graphics framework. it's low-level toolkit can use any graphics framework. doesn't have features drawing gkpath
s because there @ least many ways of interpreting path there graphics toolkits , coordinate systems with.
since you're working spritekit, it's not hard make cgpath
using same set of points gkpath
, assign skshapenode
place in scene.
you can find apple sample code inside 2 of larger demo projects: agentscatalog , demobots.
here's bit started:
// btw, vector_float2 typealias float2, // , arrayliteralconvertible, can write array shorter: let pts: [float2] = [ [-lato,maxynormalize], [+lato,maxynormalize], // ... ] // cgpoint extension make conversion more readable , reusable extension cgpoint { init(_ vector: float2) { self.init(x: cgfloat(vector.x), y: cgfloat(vector.y)) } } // make array of cgpoints array of float2 let cgpoints = pts.map(cgpoint.init) // use array create shape node let node = skshapenode(points: unsafemutablepointer(cgpoints), count: cgpoints.count)
this, of course, assumes path specified in same coordinate system scene. if not you'll need transformations.
Comments
Post a Comment