如何限制Swift 3中球的击球次数?

时间:2016-12-27 06:15:18

标签: ios swift3

我正在创建一个游戏,在第一级我希望玩家在某个时间点击圈子。例如:玩家可以获得多少次点击至少15秒。 &安培;当玩家在该特定时间限制内达到最大敲击限制时。然后,祝贺玩家。请给我一些帮助,如何建立这个。 这里有一些试图限制圆圈触摸的代码。

 let maxScore = 10
 var currentScore = 0

func playerScored(amount: Int) {

currentScore += amount

// I will be playing some sort of sound
// ...
}

override func update(_ currentTime: TimeInterval) {

if currentScore >= maxScore { // Player made it
    self.view!.presentScene(SKScene(fileNamed: "WinnerScene"))
}

2 个答案:

答案 0 :(得分:0)

我希望您知道UITapGestureRecognizer查看Apple有关点按UITapGestureRecognizer的文档,您会得到一些想法

答案 1 :(得分:-1)

  • 目标 - c 代码如下:

UITapGestureRecognizer * singleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doSingleTap)] autorelease]; singleTap.numberOfTapsRequired = 1; [self.view addGestureRecognizer:singleTap];

UITapGestureRecognizer * doubleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doDoubleTap)] autorelease]; doubleTap.numberOfTapsRequired = 2; [self.view addGestureRecognizer:doubleTap];

[singleTap requireGestureRecognizerToFail:doubleTap];

- >您可以将其转换为 swift