ios - Swift: How to get the position of SKShapeNode? -


i'm having trouble skshapenode's position. i'm storing path user touch of screen. create polygon of , put pathofshapevariable. create skshapenode of path , works fine. user drawn polygon neatly drawn on screen.

however add more stuff on polygon. reason cannot position of skshapenode. instead if try use position attribute, points x:0.0, y:0.0 below. what's going 1 here? how can actual position of skshapenode?

var pathofshape = cgpathcreatemutable()                        //path of polygon added here pathofshape var shapenode = skshapenode() shapenode.path = pathofshape  shapenode.name = "shape" self.addchild(shapenode)  let node1 = self.childnodewithname("shape") print(node1?.position) 

results optional((0.0, 0.0))

actually if make cgpath, example triangle:

var pathofshape = cgpathcreatemutable() let center = cgpointmake(cgrectgetmidx(self.frame), cgrectgetmidy(self.frame)) cgpathmovetopoint(pathofshape, nil, center.x, center.y) cgpathaddlinetopoint(pathofshape, nil, center.x + 50, center.y + 50) cgpathmovetopoint(pathofshape, nil, center.x + 50, center.y + 50) cgpathaddlinetopoint(pathofshape, nil, center.x - 50, center.y + 50) cgpathmovetopoint(pathofshape, nil, center.x - 50, center.y + 50) cgpathaddlinetopoint(pathofshape, nil, center.x - 50, center.y - 50) cgpathmovetopoint(pathofshape, nil, center.x - 50, center.y - 50) cgpathaddlinetopoint(pathofshape, nil, center.x, center.y) cgpathclosesubpath(pathofshape) 

enter image description here

and decide create skshapenode based path:

let shape = skshapenode(path: pathofshape) 

you ask center of shape:

let center = cgpointmake(cgrectgetmidx(shape.frame),cgrectgetmidy(shape.frame)) 

the correct position (0.0, 0.0) know shape.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -