- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经为此苦苦挣扎了一段时间,希望得到一些帮助!
我在 sprite kit 中有一个瓦片 map ,用户可以点击任何瓦片,事情就会发生。为了获得他们点击的图 block ,我使用了这样的东西:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInNode:_mapLayer];
SKNode *tile = [_mapLayer nodeAtPoint:touchLocation];
// Do things with the tile...
}
但是,我也希望用户能够在需要时放大和缩小 map 以获得更好的 View 。这很简单,我设置了捏合识别器并使用以下方法缩放场景:
-(void)handlePinch:(UIPinchGestureRecognizer *)recognizer {
[self runAction:[SKAction scaleBy:recognizer.scale duration:0]];
}
一切都按预期工作,除了一旦场景的比例不是 1.0,locationInNode:
方法返回错误的坐标,导致 nodeAtPoint:
退回错误的瓷砖。
例如,如果我在比例为 1.0 时点击一个图 block ,一切正常。但是,如果我将场景缩小到 0.9 比例并点击相同的图 block ,locationInNode:
会返回错误的坐标,因此将选择与我点击的图 block 不同的图 block 。
我做错了什么吗?
编辑:我创建了一张图片来说明我的问题以回应安德烈,这可能会有所帮助: http://i.imgur.com/N1XcyNx.png
最佳答案
试一试:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchLocationInView = [touch locationInView:self.scene.view];
CGPoint touchLocationInScene = [self.scene convertPointFromView:
touchLocationInView];
CGPoint touchLocationInLayer = [_mapLayer convertPoint:touchLocationInScene
fromNode:self.scene];
SKNode *tile = [_mapLayer nodeAtPoint:touchLocationInLayer];
// Do things with the tile...
}
关于ios - locationInNode : inaccurate after scaling the scene,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20114031/
我正在尝试使用 swift2.1 获取触摸位置并收到错误消息“‘UITouch’类型的值没有成员‘locationInNode’”。 这是我的代码 override func touchesBegan
我已经为此苦苦挣扎了一段时间,希望得到一些帮助! 我在 sprite kit 中有一个瓦片 map ,用户可以点击任何瓦片,事情就会发生。为了获得他们点击的图 block ,我使用了这样的东西: -(
我首先声明了两个 SKSpriteNodes,handle 和 blade,然后将 handle 添加为 self 的子节点,将 blade 添加为 handle 的子节点 var handle =
我是一名优秀的程序员,十分优秀!