-1

I making a puzzle game and I get a problem when I try to move sprite to a new position by using SKAction moveTo.

Here is my case:

I have 4 sprites in list and I want to move them to new position by putting them in for loop and using moveTo action. But moveTo cannot move the sprite immediately, it need to wait until the loop finished to move the sprite. And the problem is I use the sprite positions as a condition to stop the loop. ( for example: if sprite position reach to limit constant it cannot be moved anymore and the loop will be break)

My question: Do we have any way to make the sprite move immediately inside loop ?? Or do you know any better way to solve my case?

Any help will be appreciated.

Thank you.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
lionK
  • 27
  • 8

1 Answers1

0

Instead of a for loop, use a repeating timer. When the timer fires, move your sprites and test whether to invalidate the timer (rather than exiting a loop).

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57
  • Can you tell me a little more clearly ? I just start learning so it's a little complicating for me. Thank you so so much even you minus my point :D – lionK Nov 03 '13 at 14:03
  • No, I don't know who gave the -1. Try reading about NSTimer in the docs. You tell it how often to fire and what method to call each time. After it runs that method, normal run loop stuff happens, such as screen drawing. When you're done with it, you invalidate it and it stops. – Phillip Mills Nov 03 '13 at 14:38
  • Thank you so much, I will try. So sorry that I don't have permission to vote for you yet. I will do whenever I can. – lionK Nov 03 '13 at 16:06