我正在制作一个小游戏,但是有问题。我做了一些在屏幕上弹跳的球,目的是使屏幕上的弹跳速度相同。我的问题是,在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.0或更低。

关于ios - 弹跳节点变得疯狂,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26690502/

10-13 04:28