0

I was using performSelector to generate SKSpriteNodes after a random period of time, until a lot of people told me it was better to use dispatch_after.

What I have understood is that I need to create a function that will have the dispatch_after and then there it will point to another function that I want to do repeatedly. But this creates a problem to me. I need to pass two arguments to the method that creates the SKSpriteNodes from another class.

If I've understood correctly, in that class I need to call the method that has the dispatch_after so that it can perform the action repeatedly. Then, how would I do all of this? Do I need to pass those arguments multiple times? Also, I cannot addChild:the method that has the dispatch_after because it does not return a SKSpriteNode (the one that creates them does indeed). So, I'm really confused.

José María
  • 2,835
  • 5
  • 27
  • 42
  • Have a look at this answer: http://stackoverflow.com/a/6206301/2043580 – ZeMoon Aug 06 '14 at 11:25
  • 1
    There are SKAction methods you can use for the same. Have a look at the **Creating Custom Actions** section on the Apple [reference page](https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKAction_Ref/Reference/Reference.html) – ZeMoon Aug 06 '14 at 11:30
  • And I'm going to tell you that you shouldn't use dispatch_after either. ;) See: http://stackoverflow.com/a/23978854/201863 – CodeSmile Aug 06 '14 at 18:55
  • @joseMaria you commented on the answer he linked ^^^ on July 7th. :/ Also, on your other question for this, I suggested you use `SKAction waitForDuration:withRange:` in combination with a `SKAction runBlock:` block to get a random delay. Those suggesting `dispatch_after` are giving a more generic iOS based solution, which has significant caveats if using with SpriteKit. Please read the link above this comment again. – prototypical Aug 07 '14 at 04:17

0 Answers0