Posts

Post marked as solved
3 Replies
774 Views
I have a Swift 5 game I'm working on where I have a fade animation play after I drag a sponge image on top of another. After the animation finishes, I want it to do something, but the code in the completion part keeps happening while the animation is still playing and I don't know why. @IBAction func Clean(_ sender: UIPanGestureRecognizer) { guard let SenderView = sender.view else{ return } let translation = sender.translation(in: view) SenderView.center.x += translation.x SenderView.center.y += translation.y sender.setTranslation(.zero, in: view) sponge.center.x=SenderView.center.x sponge.center.y=SenderView.center.y if (sponge.frame.intersects(dirt.frame)) { UIView.animate(withDuration: 1.5, delay: 0, animations: { self.dirt.alpha = 0 }, completion: {(true) -> Void in self.sponge.isHidden = true }) if sender.state == .ended { sponge.center.x = view.center.x sponge.center.y = view.center.y } } }What can I do to fix this?
Posted
by esuark.
Last updated
.
Post not yet marked as solved
2 Replies
1.1k Views
I was working on a project which has one view that segues to another view. The second view's viewDidLoad contains this code:(anything not shown initialized here are initialized before viewDidLoad)override func viewDidLoad() { let views = [redView, greenView, blueView] let randomView = views[Int.random(in:0...2)] let currentView = randomView.self while score != 10{ if popupTime == nil { popupTime = Timer.scheduledTimer(withTimeInterval:1.0, repeats: true){ popupTime in if self.popupSeconds == 0 { randomView?.isHidden = false } else if self.popupSeconds <= 3 { self.popupSeconds -= 1 } } } if hideTime == nil { hideTime = Timer.scheduledTimer(withTimeInterval:1.0, repeats: true){ hideTime in if self.hideseconds == 0 { currentView?.isHidden = true } else if self.hideseconds <= 2 { self.hideseconds -= 1 } } } } super.viewDidLoad() // Do any additional setup after loading the view. }The problem is when I'm running the app and get to the part when it switches to the second view, the entire app freezes up without changing views, and no errors are shown in the console. I'm assuming it has to do with the while loop. If I remove the while loop, the view switches and the code runs one time just fine.I'll try to provide as much information as needed, and any help would be greatly appreciated!
Posted
by esuark.
Last updated
.
Post not yet marked as solved
5 Replies
454 Views
I am currently working on a project which uses 3 UIImages and UITapGestureRecognizers, one for each image. I wanted to set up all three gesture recognizers to a single @IBAction, so when one image gets tapped, only that image is hidden. This is basically what I have:@IBAction func handleTap(_ sender: UITapGestureRecognizer) { sender.view?.isHidden=true }None of the images hide after I tap them, and I wasn't seeing anything online on how to fix it.Any help would be greatly appreciated!
Posted
by esuark.
Last updated
.
Post not yet marked as solved
1 Replies
332 Views
I'm currently making a 2d game and am trying to add a part where you drag one UIImageView on top of another, and when they touch then something happens. I'm pretty new to Swift so I don't know what the code is for collisions.If sprite1 is touching sprite2{ somethingHappens() }else{ somethingElseHappens() }Any help would be greatly apprecitated! 🙂
Posted
by esuark.
Last updated
.
Post marked as solved
4 Replies
382 Views
I have a game I'm working on which uses the UIAlertController to change a String variable for the player's gender pronouns.class GameViewController: UIViewController { var hes="" var TapChat = 0 let gender = UIAlertController(title: "About Me", message: "I am a...", preferredStyle: .alert) let female = UIAlertAction(title: "Female", style:.default) { (female) in self.hes="she's" //ERROR: Value of type '(GameViewController) -> () -> GameViewController' has no member 'hes' } //I have the alert presented within a switch case inside a UITapGestureRecognizer IBAction func {{ self.gender.addAction(self.female) self.present(gender, animated:true, completion:nil) //case and IBAction func end }} override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } }
Posted
by esuark.
Last updated
.