我已经使用touchesBegan为我的UIButtons提供功能,并已使用轻击手势为我的主玩家SKSpriteNode提供功能,使其在触发时跳转。点击手势不会发生时触摸特定的位置 - SpriteKit
//代码有关的UIButton触摸
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
//touches began is only used for GUI buttons -> not to affect player
for touch: AnyObject in touches {
//We get location of the touch
let locationOfTouch = touch.location(in: self)
if muteButton.contains(locationOfTouch) { //mute the game
timer.invalidate()
audioPlayer.volume = 0
}
//守则关于自来水
let tap = UITapGestureRecognizer(target: self, action: #selector(GameScene.tapped(gesture:)))
tap.cancelsTouchesInView = false
self.view!.addGestureRecognizer(tap)
......
func tapped(gesture: UIGestureRecognizer) { //used to make the player jump
player.physicsBody!.applyImpulse(CGVector(dx: 0, dy: 60))
player.physicsBody!.affectedByGravity = true */
}
我的问题是,当我按在restartButton点击手势也将在后面启动的时候,触摸结束。有什么我可以做的吗?
您是否有使用单独的水龙头手势识别器的具体原因?如果用户不触摸按钮,为什么不在“touchesBegan”中包含播放器跳转代码? – nathan
我正在使用不同的水龙头手势,因为我也使用了滑动功能,在这种情况下,如果我使用touchesBegan,则无法区分并识别滑动。 –
当您重新启动场景时,您是否创建并呈现新场景? – Knight0fDragon