ios - PanGesture 后按钮位置未正确更新
问题描述
当我使用 Pan Gesture 在 Tilemap 背景中移动时,我已将按钮设置为随相机移动的位置。但是,当我单击按钮时,它不起作用。如果我打开场景并且不使用平移手势移动相机,它会起作用。所以,我假设按钮的位置没有正确更新,尽管它明显随着相机移动。
这是运动发生之前场景的第一部分。 这是我使用平移手势后的第二部分场景。
正如您从照片中看到的那样,按钮正在按照我的意愿移动。但是,当我单击 Rim 图像时,它在第二个图像中无法正常工作。
以下是我的相关代码:
func addButtonstoScene()
{
//Hint Button
buttonHint.position = CGPoint(x: (camera?.position.x)! + buttonHintXOffset, y: (camera?.position.y)! + buttonYOffset)
buttonHint.name = "Hint"
buttonHint.size = CGSize(width: buttonWidth, height: buttonHeight)
buttonHint.isHidden = false
//Fast Forward Button
buttonFastForward.position = CGPoint(x: (camera?.position.x)! + buttonFastForwardXOffset, y: (camera?.position.y)! + buttonYOffset)
buttonFastForward.name = "Hint"
buttonFastForward.size = CGSize(width: buttonWidth, height: buttonHeight)
buttonFastForward.isHidden = false
//Settings Button
buttonSettings.position = CGPoint(x: (camera?.position.x)! + buttonSettingsXOffset, y: (camera?.position.y)! + buttonYOffset)
buttonSettings.name = "Settings"
buttonSettings.size = CGSize(width: buttonWidth, height: buttonHeight)
buttonSettings.zPosition = 2000
camera?.addChild(buttonHint)
camera?.addChild(buttonFastForward)
camera?.addChild(buttonSettings)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
{
for touch in touches
{
let location = touch.location(in: self)
if buttonSettings.contains(location)
{
let transitions: SKTransition = SKTransition.doorway(withDuration: transitionTime)
let scene: SKScene = OptionsScene(size: CGSize(width: 2048, height: 1536))
scene.scaleMode = .aspectFill
self.view?.presentScene(scene, transition: transitions)
}
}
}
解决方案
因此,经过一段时间试图找出我做错了什么之后,我能够解决这个问题。更正是有位置(在:相机!)
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
{
for touch in touches
{
let location = touch.location(in: camera!)
if buttonSettings.contains(location)
{
let transitions: SKTransition = SKTransition.doorway(withDuration: transitionTime)
let scene: SKScene = OptionsScene(size: CGSize(width: 2048, height: 1536))
scene.scaleMode = .aspectFill
self.view?.presentScene(scene, transition: transitions)
}
}
}
推荐阅读
- angular - 如何使用 Angular 8 在不同浏览器上的同一网页之间同步数据
- vitess - 我们可以分片特定的表而不在 vitess 中创建新的键空间吗?
- php - Laravel 不会捕获 \Exception、\Throwable,也不会捕获任何东西
- c# - 等到类从 div 中删除
- c# - 如何使用asp.net c#拆分字符串数据并推送到具有特定格式的数据表?
- android - Bottomsheet 显示在 RecyclerView - 如何确保单击的项目显示在 RecyclerView
- sql - 将查询转换为 Eloquent
- python - 如何在pandas DataFrame的值列中找到顺序(数字|增加|减少)的最高计数
- c# - 在 C# 中调用 COM+ 对象事件处理程序
- python - 如何通过python从https://online.aia.edu.au/登录下载csv文件