当我使用“平移手势”在Tilemap背景周围移动时,我已将按钮设置为随相机移动的位置。但是,当我单击按钮时,它不起作用。如果我打开场景并且不使用“平移手势”移动相机,则此方法有效。因此,我假设该按钮的位置没有正确更新,尽管它已随相机一起明显移动。
View Example This is the First part of the Scene before movement occurs.
从照片中可以看到,按钮正在按我希望的方式移动。但是,当我单击“边框”图像时,它在第二个图像中无法正常工作。
下面是我的相关代码:
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)
}
}
}
答案 0 :(得分:0)
因此,经过一段时间尝试找出我做错了什么,我才得以解决。更正的是要找到位置(在相机上!)
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)
}
}
}