0

I have a an SKSpriteNode for my _player and there are two children to the _player node that make up my character.

the sprites with this configuration have the character facing right.

when I need the character to face left I tried using xScale = -1.0 but when I do that it does not appear that the frames reflect what is seen on the screen because my CGRectIntersectsRect behaves as if the character was still facing the original direction.

in addition to the cgrect problem I was rotating the character towards objects so I end up having to do something like this:

 if( sprite.xScale == -1.0){
    sprite.zRotation = atan2f(direction.y, direction.x);
    } else {
        sprite.zRotation = atan2f(-direction.y, -direction.x);
    }

Whats the proper way to flip the player. It seems like the math is going to get unnecessarily complicated for my collision detections if I use xScale. Do I need two instances of the player one facing each direction. Do I need two sets of sprites?

Early73
  • 473
  • 3
  • 7
  • 23
  • Did you ever resolve this? I'm wondering how to deal with a sprite which can be "looking" left or right, and needs to have a field of vision in that direction... – Ben Wheeler Jun 04 '15 at 18:01

2 Answers2

0

Here is a tutorial that may solve your problem. http://www.raywenderlich.com/45152/sprite-kit-tutorial-animations-and-texture-atlases I found it very helpful. the bear in the project flips depending on what side of the screen you touch. number 6 is where I believe your answer is...

  • Thanks for the reply. They are using xScale the same way I was above but for them it was not as complicated because there aren't any children nodes to their character. also their character is the same shape forwards and backwards so they wouldn't have the same problem detecting collisions that I have. – Early73 Feb 21 '14 at 22:30
0

this is late but I think I found a solution to this. Make a global node (that keeps track of position) and add your xscale, yscale node as a child to this global node. You can keep track of position (global) now without worrying about the -xscale/-yscale (child) affecting the position lookup on the scene.

user222864
  • 81
  • 7