ios - Converting between coordinate spaces SpriteKit -
i have node shape of box in scene. shape node should have own coordinate space, if declare point @ (100,100) in nodes coordinate space , rotate box pi/4 rad point should change in scenes coordinate space.
my problem cant work, i'm using following code convert point in nodes coord space scenes coord space, placement of node 200,200 in scene:
startpointinnodespace = cgpointmake(0, size.height/2); cgpoint start = [self.scene convertpoint:cgpointmake(startpointinnodespace.x, startpointinnodespace.y) fromnode:self.parent]; cgpoint end = [self.scene convertpoint:cgpointmake(startpointinnodespace.x, startpointinnodespace.y + 100) fromnode:self.parent]; nslog(@"start position in node: (%f,%f)\nend position in node: (%f,%f)",startpointinnodespace.x,startpointinnodespace.y,startpointinnodespace.x,startpointinnodespace.y + 100); nslog(@"start position in scene: (%f,%f)\nend position in scene: (%f,%f)",start.x,start.y,end.x,end.y);
the code inside subclass of skspritenode
.
my log:
start position in node: (0.000000,20.000000) end position in node: (0.000000,120.000000) start position in scene: (0.000000,20.000000) end position in scene: (0.000000,120.000000)
as can see not converting points @ dont know doing wrong.
visual illustration of want achieve:
i think problem you're converting self.parent
instead of self
— node's parent is scene, there's no conversion done. try converting self
instead:
startpointinnodespace = cgpointmake(0, size.height/2); endpointinnodespace = cgpointmake(startpointinnodespace.x, startpointinnodespace.y + 100); cgpoint start = [self.scene convertpoint:startpointinnodespace fromnode:self]; cgpoint end = [self.scene convertpoint:endpointinnodespace fromnode:self];
(note can pass startpointinnodespace
method, rather creating identical point. structs copied value, method can't mutate variable.)
Comments
Post a Comment