gpt4 book ai didi

ios - SpriteKit - 停止物体弹跳

转载 作者:行者123 更新时间:2023-12-03 02:14:00 24 4
gpt4 key购买 nike

我如何停止并阻止从屏幕顶部落到屏幕底部的弹跳。这是该对象的代码:

- (SKNode*)addRock {
SKSpriteNode* rock = [SKSpriteNode spriteNodeWithImageNamed:@"asteroid"];
rock.position=CGPointMake ([self makeRandomXWBetween:0 and:self.size.width],self.size.height);
rock.name = @"rock";
rock.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:rock.size];
rock.physicsBody.usesPreciseCollisionDetection = YES;
rock.physicsBody.allowsRotation = NO;
[self addChild:rock];

return self;
}

最佳答案

您需要设置SKPhysicsBody的恢复属性。

rock.physicsBody.restitution = 0.0;

根据 Apple 的 Documentation :

This property is used to determine how much energy the physics body loses when it bounces off another object. The property must be a value between 0.0 and 1.0. The default value is 0.2.

关于ios - SpriteKit - 停止物体弹跳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23948472/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com