mardi 1 août 2017

Combine if statement

I am trying to combine the two "if" statements below, so that if the first "if" statement happens, then the second "if" statement can be executed. The problem is that whiteDot cannot be two places at once. With this code I have, whiteDot has to be inside the center and also covering whiteDot which isn't possible. whiteDot is draggable via PanGesture. My question is, how can I edit this code so that every time the first "if" statement happens the second "if" statement can be executed. So you have to drag whiteDot into the center, so the second "if" statement can be executed. when the whiteDot is dragged out of the center, and is then dragged and covering smallDot the second "if" statement is executed, but only if the whiteDot has been inside the center first. Hopefully pictures help clear up confusion. It is hard to explain without video.

  if center.frame.contains(whiteDot.frame) {

        if (whiteDot.frame.contains(smallDot.frame) && smallDot.image != nil) {
            addOne += 1
            score.text = "\(addOne)"
            print("plus 1")
            resetTimer()
            whiteDot.spawnRandom
            timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(SecondViewController.startTimer), userInfo: nil, repeats: true)   
            smallDot.center = spawnRandomPosition()  
          }
      }

[![enter image description here][1]][1] [1]: http://ift.tt/2wju12g [![enter image description here][2]][2][2]: http://ift.tt/2vr87Op [![enter image description here][3]][3] [3]: http://ift.tt/2wjg1Wc [![enter image description here][4]][4][4]: http://ift.tt/2vr1JXq

Aucun commentaire:

Enregistrer un commentaire