弹跳节点变得疯狂

时间:2014-11-01 14:59:56

标签: ios objective-c sprite-kit

我正在构建一个小游戏,但有问题。我制作了一些在屏幕上反弹的球,这意味着屏幕上的反弹速度相同。我的问题是,在30秒之后,球会疯狂地在屏幕上尽快反弹。我该如何解决?

这是我的代码:

  int maxXCoord = self.frame.size.width;
int maxYCoord = self.frame.size.height;

int circleWidth = 6;

int x = arc4random() % (maxXCoord - (circleWidth / 2));
int y = arc4random() % (maxYCoord - (circleWidth / 2));

   SKSpriteNode* _numberint = [SKSpriteNode spriteNodeWithImageNamed: @"red.png"];
_numberint.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:(_numberint.frame.size.width/2)];

    _numberint.position = CGPointMake(x,y);


    _numberint.physicsBody.contactTestBitMask = ballCatagoryName;
    _numberint.physicsBody.collisionBitMask = ballCatagoryName;


     _numberint.physicsBody.friction = 0.8f;
_numberint.physicsBody.restitution = 1.2f;
_numberint.physicsBody.linearDamping = 0.0f;
_numberint.physicsBody.angularDamping = 0.0f;
_numberint.physicsBody.allowsRotation = NO;

[_numberint.physicsBody applyImpulse:CGVectorMake(8.0f, -8.0f)];

[self addChild:_numberint];

谢谢!

1 个答案:

答案 0 :(得分:1)

如果将恢复原状设置为大于1.0的值,则每次碰撞时对象都会加快速度。将恢复原状设置为1.0或更低。