gpt4 book ai didi

ios - SpriteKit 重力混淆

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:19:40 26 4
gpt4 key购买 nike

我有以下 SpriteKit 代码:

scene.physicsWorld.gravity = CGVectorMake(0, -10);
...
- (void)update:(CFTimeInterval)currentTime
{
[node.physicsBody applyForce:CGVectorMake(0, 10 * node.physicsBody.mass)];
}

为什么 applyForce 不能平衡重力?节点向下坠落的速度非常快。

完整示例:

@interface HelloScene()

@property SKLabelNode *node;

@end

@implementation HelloScene

- (void)didMoveToView:(SKView *)view
{
self.backgroundColor = [SKColor blueColor];
self.scaleMode = SKSceneScaleModeAspectFit;
self.physicsWorld.gravity = CGVectorMake(0, -10);
[self addChild:[self newHelloNode]];
}

- (SKNode *)newHelloNode
{
self.node = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
self.node.text = @"Hello, World!";
self.node.fontSize = 42;
self.node.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
self.node.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:10.0];
self.node.physicsBody.mass = 1.0;
self.node.physicsBody.angularDamping = 0.0;
self.node.physicsBody.linearDamping = 0.0;
self.node.physicsBody.friction = 0.0;
return self.node;
}

- (void)update:(NSTimeInterval)currentTime
{
[self.node.physicsBody applyForce:CGVectorMake(0, 10 * self.node.physicsBody.mass)];
}

@end

编辑:

看起来它超出了 150 倍。这似乎有效:

self.physicsWorld.gravity = CGVectorMake(0, -10.0/150.0);

为什么会这样?

最佳答案

看起来@mitchellallison 已经做了一些实验,发现这是由于像素与米的比率。参见 applyForce(0, 400) - SpriteKit inconsistency

关于ios - SpriteKit 重力混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20556549/

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