我已经使自己成为一个非常基本的应用程序,可以计算你的水龙头并为每个水龙头提供一个很好的“ping”。我想要帮助的是在某些地标上你得到一个不同的声音,有点像用户做得好。我该怎么做才能使每100的倍数发出与往常不同的声音?
import UIKit
import AVFoundation
class ViewController: UIViewController {
@IBOutlet weak var background1: UIImageView!
@IBOutlet weak var counterLabel: UILabel!
@IBOutlet weak var button: UIButton!
var tapSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("schwing", ofType: "mp3")!)
var audioPlayer = AVAudioPlayer()
var playerScoreTotal = 0
override func viewDidLoad() {
super.viewDidLoad()
audioPlayer = AVAudioPlayer(contentsOfURL: tapSound, error: nil)
audioPlayer.prepareToPlay()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func screenTapped(sender: AnyObject) {
audioPlayer.play()
playerScoreTotal += 1
self.counterLabel.text = String(playerScoreTotal)
self.counterLabel.textColor = UIColor.redColor()
self.button.setTitle("", forState: UIControlState.Normal)
}
}
答案 0 :(得分:1)
您可以使用不同的声音创建第二个音频播放器。
然后您可以将此检查添加到您的函数中:
if ((playerScoreTotal % 100) != 0){
//Play the original sound
}
else{
//Play the **second** sound, do other stuff
}
//Do your other updates here