In this drag and drop game (adapted from this tutorial), the player has to match the label to the right target. I have it set so that if the touch ends and the label's center is inside the target, it is removed from the screen and the game starts over.
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
if label.name == "letters" {
if lettersBin.frame.contains(label.position) {
// remove it and create a new label
label.removeFromParent()
setupDragLabel()
However, I want to trigger a notification if the player drops the wrong label onto the bin, so:
else if label.name == "numbers" {
if lettersBin.contains(label.position) ...
What would I write to finish this? Do I make another label appear on the screen?
It might be easiest to use a UIAlertController. You can add the messages along with button actions to display that the user was wrong.
let converterAction = UIAlertController(title: "Your title here", message: "Your message to the user here", preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .default){ _ in
//Any custom action to happen here
}
converterAction.addAction(okAction)
present(converterAction, animated: true, completion: nil)