Delay in a method

I have code for spawning an enemy then making the enemy run towards the player until he reaches him. However, I’m now trying to make en enemy that runs towards the player for a short distance, stop, then carry out another action. The only problem is I have no idea how to implement a delayed response in a method without interrupting the flow of the game. Ideally, the enemy would use the same method the chasing enemies do, then after a certain amount of time has passed, call a method that stops him. How can I implement this? [import]uid: 89724 topic_id: 16136 reply_id: 316136[/import]

Take a look at timer.performWithDelay()

http://developer.anscamobile.com/reference/index/timerperformwithdelay [import]uid: 44101 topic_id: 16136 reply_id: 60108[/import]

The closure plus the “dodgy hack” in the first comment worked nicely. And it’s certainly much better than my initial solution to create a spawnTime attribute and check every frame to see if the timer was a certain amount over that variable. Thanks. [import]uid: 89724 topic_id: 16136 reply_id: 60156[/import]