Scaling Physics Bodies in Xcode Spritekit

后端 未结 2 414
终归单人心
终归单人心 2020-12-10 19:38

I recently came across an issue where I would increase the size of a node, but the physics body would remain the same size. I tried to look up solutions to this with no succ

2条回答
  •  無奈伤痛
    2020-12-10 19:52

    this is strange you can do it add physics body before adding it to the SKNode or SKScene for e.g.

    SKTexture  *texture=[_gameTexture textureNamed:@"mysprite"];
    SKSpriteNode *bubble=[SKSpriteNode spriteNodeWithTexture:texture];
    bubble.anchorPoint=CGPointMake(0.5,0.5);
    //_bubble.name=[@"bubble" stringByAppendingFormat:@"%d ",index];
    bubble.name=newcolor;
    

    // _bubble.userInteractionEnabled=YES; _bubble.position=CGPointMake(newPosition.x, newPosition.y);

    //
    bubble.physicsBody=[SKPhysicsBody bodyWithCircleOfRadius:60];
    bubble.physicsBody.dynamic=NO;
    bubble.physicsBody.linearDamping=0;
    bubble.physicsBody.restitution=0;
    
    
    bubble.physicsBody.density=1;
    bubble.physicsBody.allowsRotation=NO;
    bubble.physicsBody.affectedByGravity=NO;
    //_bubble.physicsBody.velocity=CGVectorMake([self getRandomNumberBetween:-10 to:7], [self getRandomNumberBetween:-10 to:7]);
    //  _bubble.physicsBody.usesPreciseCollisionDetection=YES;
    
    
    bubble.physicsBody.categoryBitMask=ballCategory;
    bubble.physicsBody.collisionBitMask=ballCategory | pathCategory ;
    bubble.physicsBody.contactTestBitMask=ballCategory | pathCategory ;
    
    [self addChild:_bubble];
    
    
    bubble.xScale=_bubble.yScale=2;
    bubble.alpha=0.5;
    

提交回复
热议问题