gpt4 book ai didi

ios - Spritekit PhysicsBody applyTorque

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

我正在开发一款通用应用。

我想applyTorque到桨

但问题是 ipad 上的桨尺寸比 one one iphone 的要大。

如何计算扭矩以对桨的物理主体施加相同的影响?

SKSpriteNode *bar = [SKSpriteNode spriteNodeWithImageNamed:nameImage];
bar.name = @"bar";
bar.size = CGSizeMake(PaddleWidth, PaddleHeight);
bar.physicsBody =[SKPhysicsBody bodyWithTexture:bar.texture size:bar.size];
bar.physicsBody.restitution = 0.2;
bar.physicsBody.angularDamping = 0;
bar.physicsBody.friction = 0.02;
bar.physicsBody.mass=.2;
[paddle addChild:bar];
SKSpriteNode *anchor = [SKSpriteNode spriteNodeWithColor:[SKColor clearColor] size:CGSizeMake(PaddleWidth, PaddleHeight)];
anchor.name = @"anchor";
anchor.size = CGSizeMake(PaddleHeight, PaddleHeight);
anchor.position = CGPointMake(bar.position.x + bar.size.width/2, 0);
[paddle addChild:anchor];

CGFloat anchorRadius = anchor.size.width/20;

anchor.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:anchorRadius];
anchor.physicsBody.dynamic = NO;
CGPoint positionInScene = [self convertPoint:anchor.position toNode:self.scene];

pin = [SKPhysicsJointPin jointWithBodyA:bar.physicsBody
bodyB:anchor.physicsBody
anchor:positionInScene];
pin.shouldEnableLimits = YES;
pin.lowerAngleLimit = -0.5;
pin.upperAngleLimit = 0.5;
[self.scene.physicsWorld addJoint:pin];

-(无效)翻转{

SKNode *bar=[self childNodeWithName:@"bar"];
CGFloat torque;
torque=10;
[bar.physicsBody applyTorque:torque];

最佳答案

您可以使用桨的大小作为扭矩值的一个因素:

CGSize paddleSize = <Initialize with paddle size>
CGFloat torque=paddleSize.width * factor; // factor will be the value you need to multiply in order to reach your desired value

因此,例如,如果 Racket 宽度为 100,请使用常数因子 0.05在 iPad 上,不同的桨宽度将使用与上述相同的系数值相应地计算扭矩值。

关于ios - Spritekit PhysicsBody applyTorque,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30588923/

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