我正在开发通用应用程序。
我想applyTorque
到桨
但是问题在于,ipad上的拨片尺寸比一个iphone大。
如何计算将相同影响施加到Paddle的physicalBody的扭矩?
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
因此,例如,如果桨叶宽度为
100
,则使用常数0.05
在iPad上,不同的拨片宽度将使用与上述相同的系数值相应地计算扭矩值。关于ios - Spritekit PhysicsBody applyTorque,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30588923/