Adding delay between execution of two following lines

前端 未结 7 1853
陌清茗
陌清茗 2020-12-07 13:15

I need to add delay between the execution of two lines in a(same) function. Is there is any favorable options to do this?

Note: I don\'t need two di

7条回答
  •  半阙折子戏
    2020-12-07 13:40

    I have a couple of turn-based games where I need the AI to pause before taking its turn (and between steps in its turn). I'm sure there are other, more useful, situations where a delay is the best solution. In Swift:

            let delay = 2.0 * Double(NSEC_PER_SEC) 
            let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay)) 
            dispatch_after(time, dispatch_get_main_queue()) { self.playerTapped(aiPlayView) }
    

    I just came back here to see if the Objective-C calls were different.(I need to add this to that one, too.)

提交回复
热议问题