gpt4 book ai didi

ios - 平移手势后按钮位置未正确更新

转载 作者:行者123 更新时间:2023-11-30 11:15:00 24 4
gpt4 key购买 nike

当我使用平移手势在 Tilemap 背景周围移动时,我已将按钮设置为随相机移动的位置。但是,当我点击按钮时它不起作用。如果我打开场景并且不使用平移手势移动相机,它就会起作用。因此,我假设按钮的位置没有正确更新,尽管它明显随相机移动。

This is the First part of the Scene before movement occurs. This is the second part of the Scene after I have used the Pan Gesture.

正如您从照片中看到的,按钮正在按照我想要的方式移动。但是,当我单击 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)
}
}
}

关于ios - 平移手势后按钮位置未正确更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51826309/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com