Search code examples
objective-cxcodescalesprite-kitios7.1

Sprite Kit - object colliding because of scale after iOS 7.1 update


There was no problem but after iOS 7.1 update, object is colliding 2pipes' gap. Someone said before, it can be because of 'yScale' but I couldn't find the solution.

Some code;

  Pipe *pipe = [[Pipe alloc] initWithImageNamed:pipeImageName];
  [pipe setCenterRect:CGRectMake(26.0/kPipeWidth, 26.0/kPipeWidth, 4.0/kPipeWidth, 4.0/kPipeWidth)];
  [pipe setYScale:height/pipe.size.height];
  [pipe setPosition:CGPointMake(320+(pipe.size.width/2), abs(pipeYOffset + (pipe.size.height/2)))];

  pipe.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:pipe.size];
  [pipe.physicsBody setAffectedByGravity:NO];
  [pipe.physicsBody setDynamic:NO];

Any help will be appreciated. Thank you!


Solution

  •   Pipe *pipe = [[Pipe alloc] initWithImageNamed:pipeImageName];
      [pipe setCenterRect:CGRectMake(26.0/kPipeWidth, 26.0/kPipeWidth, 4.0/kPipeWidth, 4.0/kPipeWidth)];
    
    //set the physicsBody before X/Yscale
      pipe.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:pipe.size];
    
      [pipe setYScale:height/pipe.size.height];
      [pipe setPosition:CGPointMake(320+(pipe.size.width/2), abs(pipeYOffset + (pipe.size.height/2)))];
    
      [pipe.physicsBody setAffectedByGravity:NO];
      [pipe.physicsBody setDynamic:NO];
    

    This may help you. I think this is a bug in ios7.1.