Spritekit和UIKit坐标之间的冲突

时间:2014-07-09 13:34:10

标签: ios7 coordinates sprite-kit

我有一个问题,我认为应该有一个简单的答案(我还没有找到!)。在我的SKScene中,所有节点都定位并沿路径正确移动(基于左下角的原点)但是当我在此视图中收集用户触摸坐标时(下面的代码),这些是基于UIKit原点返回的(左上)。我确定我在这里遗漏了一些非常简单的东西;任何帮助将不胜感激!

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {  

        UITouch *move=[[event allTouches] anyObject];
        CGPoint movepoint=[move locationInView:self.view];
        [_guide runAction:[SKAction moveTo:[[touches anyObject] locationInNode:self] duration:0.01 ]];

        if (recording){
            if (_MovePointsArray==NULL) {
                _MovePointsArray=[[NSMutableArray alloc]init];
            }
            [_MovePointsArray addObject:[NSValue valueWithCGPoint:movepoint]];
        }
        curx=[NSString stringWithFormat:@"%f", movepoint.x];
        myXPos.text=curx;
        cury=[NSString stringWithFormat:@"%f", movepoint.y];
        myYPos.text=cury;
}

1 个答案:

答案 0 :(得分:0)

替代

CGPoint movepoint = [move locationInView:self.view];

使用

CGPoint movepoint = [move locationInNode:self];

每个

的签名
- (CGPoint)locationInView:(UIView *)view
- (CGPoint)locationInNode:(SKNode *)node