Bonjour,
J’essaie de créer un super simon mais j’ai quelques problèmes pour que la fonction aléatoire joue une musique avec le changement de couleur du bouton ( 3 boutons au total ). La boucle n’attend pas la fin du timer pour lancer l’action suivante
Merci de votre aide - Lionel
func switchColor( Case : UIButton, NumButton : Int)
{
switch NumButton {
case 1 :
Case.backgroundColor = UIColor.yellow
AVplayer(nom: "do")
Timer.scheduledTimer(withTimeInterval: 0.5, repeats: false, block: { (timer : Timer) in
Case.backgroundColor = UIColor.blue } )
case 2 :
Case.backgroundColor = UIColor.yellow
AVplayer(nom: "re")
Timer.scheduledTimer(withTimeInterval: 0.5, repeats: false, block: { (timer : Timer) in
Case.backgroundColor = UIColor.red } )
case 3 :
Case.backgroundColor = UIColor.yellow
AVplayer(nom: "mi")
Timer.scheduledTimer(withTimeInterval: 0.5, repeats: false, block: { (timer : Timer) in
Case.backgroundColor = UIColor.green } )
default : break
}
}
@IBAction func ui_debut_jeu() {
var i : Int = 0
repeat {
aleatoire() // appel de la fonction aléatoire pour rajouter une note supplémentaire dans la liste
nombredeligne = nombre.count
for i in 1...nombredeligne {
let boutoncalcul = nombre[i-1]
playcolor(NumButton: boutoncalcul)
testbutton()
}
}
while reponse == true
print("Erreur")