i've got path , skshapenode , have skshapenode follow path forever (hexagon shape).
let pathhexagon:skshapenode = skshapenode() let player:skshapenode = skshapenode() pathhexagon.path = playerhexagonpath(pathhexradius) pathhexagon.position = cgpoint(x: cgrectgetmidx(frame), y: cgrectgetmidy(frame)) pathhexagon.strokecolor = uicolor.blackcolor() pathhexagon.linewidth = 5 addchild(pathhexagon) player.path = playerpath(playersize) player.position = cgpoint(x: cgrectgetmidx(frame), y:cgrectgetmidy(frame)) player.strokecolor = uicolor.blackcolor() player.fillcolor = uicolor.blackcolor() addchild(player) let action = skaction.followpath(playerhexagonpath(pathhexradius), speed: cgfloat(300.0)) player.runaction(skaction.repeatactionforever(action))
it works starting position changes every cycle:
why happening?
eventually link animation user input. practice trying replicate super hexagon. if know better approach please let me know well.
this asoffset
parameter does:
@param asoffset if yes, points in path relative offsets node’s starting position. if no, points in node absolute coordinate values.
so understanding, when set false, points path absolute coordinate values in coordinate system of node's parent.
you can 2 things make work:
1) make container , add player it
2) change scene's anchor point, doubt suits because have re-position everything.
probably there few more ways solve this, haven't tried myself.
option 1:
let container = sknode() player.path = playerpath(playersize) player.position = cgpoint(x: 0, y: 0) player.strokecolor = uicolor.blackcolor() player.fillcolor = uicolor.blackcolor() container.addchild(player) container.position = cgpoint(x:frame.midx, y:frame.midy) addchild(container) let action = skaction.followpath(pathhexagon.path!, asoffset: false, orienttopath: true, speed: cgfloat(300.0)) player.runaction(skaction.repeatactionforever(action))
or, option two:
self.anchorpoint = cgpoint(x:0.5, y:0.5) mainhexagon.path = hexagonpath(mainhexradius) mainhexagon.strokecolor = uicolor.redcolor() mainhexagon.linewidth = 10 addchild(mainhexagon) pathhexagon.path = playerhexagonpath(pathhexradius) pathhexagon.strokecolor = uicolor.blackcolor() pathhexagon.linewidth = 5 addchild(pathhexagon) player.path = playerpath(playersize) player.position = cgpoint(x: 0, y: 0) player.strokecolor = uicolor.blackcolor() player.fillcolor = uicolor.blackcolor() addchild(player) let action = skaction.followpath(pathhexagon.path!, asoffset: false, orienttopath: true, speed: cgfloat(300.0)) player.runaction(skaction.repeatactionforever(action))
Comments
Post a Comment