0

I need to spawn 4 new SKSpriteNodes (independent not parented) at the corners of an existing sprite. Its pretty basic stuff but I am struggling to find the correct formula, I though I had it but its not working as expected. Could some either point me towards the correct formula or help me out with some guidance on calculating the 4 [x, y] pairs for any given rotation. Much appreciated.

enter image description here

  1. Move rotation center for each point to origin.
  2. xnew = x * cos(angle) - y * sin(angle)
  3. ynew = y * cos(angle) + x * sin(angle)
  4. Move rotation center for each point back to original position.
fuzzygoat
  • 26,573
  • 48
  • 165
  • 294

1 Answers1

1

You could use CGPointApplyAffineTransform along with CGAffineTransformMakeRotation if you didn't want to do the math yourself. Your math though looks almost right at first glance, I believe you just need to subtract out the center point. So xnew would be (x - x_c) * cos(a) - (y - y_c) * sin(a). Can't test right now so can't be 100% sure.

Matt
  • 4,849
  • 3
  • 26
  • 23
  • Thanks Matt, I will look at those, much appreciated. – fuzzygoat Oct 03 '13 at 15:52
  • Matt, I have not had chance to try this yet but I have read the docs and it would seem to be just what I need, thank you again for taking the time to answer. – fuzzygoat Oct 03 '13 at 18:01