- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在开发一款通用应用。
我想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/
我正在用 swift 3 和 spritekit 制作一个游戏,我需要一种方法让一个带有物理体的物体穿过另一个物理体,同时仍然检测碰撞但不会反弹(有点像检查点系统,所以我可以告诉玩家经历了多少个阶段)
因此,在我的 Space Invaders 游戏中,所有碰撞都完美运行,直到我添加了一个从 edgeChainFromPath 创建的物理体,它是代表地面的一条线(从 2 个点创建的 SKShapeN
最近发现有些sprite节点无法测试与其他sprite节点的碰撞。经过几天的尝试和谷歌搜索,我终于让它们照常工作。我已经意识到动态和类别位掩码之间似乎存在某种关系。我的猜测是: player.dyna
我在我的代码中声明了各种位掩码类别,如下所示: static const uint32_t playerCategory = 1; static const uint32_t enemyCategor
我有一个附有立方体的节点,例如代表一扇门。 physicsbody 类型是.static。如果我向上动画节点,旋转它并将它向下动画到 physicsbody 的原始位置保持在上部位置。在 Debug模
协议(protocol)如下。我的球掉落,击中地板,然后在以下代码的帮助下弹回来 ball.physicsBody?.applyImpulse(CGVectorMake(0, 25)) 但是,有时球会
在带有 SpriteKit 的 IOS 7 中,如何只移除物理体而将节点留在场景中?我试图让碰撞发生,然后让汽车 Actor 冲破障碍墙。 for (SKSpriteNode *node in _ob
首先我添加了 skView.showsPhysics = YES; 查看物理 body 电路。 但是 我有失去物理效果的问题 O_o...我有一个受重力影响并掉落的球。 // Ball sel
我如何才能完全消除我的 PhysicsBodies 的弹跳,我已经将所有 PhysicsBodies 的恢复设置为 0,但是当多个 PhysicsBodies 发生碰撞时,它们仍然会相互反弹,如何才能
测试代码如下: var paths = UIBezierPath() var bottomLeft = CGPoint(x: dim.minX, y:dim.minY) var bottomRight
我已经摆弄这个话题大约三个月了。我以为这只是苹果很快会修复的一个临时错误,并将其推迟到开发结束。现在我的游戏快结束了,但我仍然找不到好的解决方法: 如果我有一个 SKShapeNode 并向其添加一个
我正在开发一款通用应用。 我想applyTorque到桨 但问题是 ipad 上的桨尺寸比 one one iphone 的要大。 如何计算扭矩以对桨的物理主体施加相同的影响? SKSpriteNod
我有这个对象,它有一个从路径创建的 physicsBody。 整个场景区域(=整个屏幕)本身就是该对象不应逃脱的边界。 这个场景的边界定义为 self.physicsBody = [SKPhysics
我正在尝试获取两个已经相互接触的 physicsBody(实际上它们重叠,因为 physicBody.collisionCategory = 0;对于两个 physicsBody),以重新启动/重新注
我创建了一个 SKShapeNode 并为其分配了一个 physicsBody。但是,当有接触时它不会被触发。 创建SKShapeNode代码: -(SKShapeNode*)gravityline{
我正在使用 SpriteKit 实现质量 Spring 系统(许多小型物理体与 SKPhysicsJointSpring 实例连接在一起)。一些粒子在穿过场景中心时会被卡住。 场景中间似乎有一个静止的
这是我的玩家类 我的播放器不会与 Gamefield 发生碰撞,它们只是相互穿过。我不希望他们彼此重叠。我试着用谷歌搜索解决方案,但对我来说,我似乎基本上做得很好。 请帮助: class Player
以下代码识别场景的底部和顶部边缘,并且球按预期反弹。然而,场景的左边缘和右边缘总是被破坏。如果施加足够的力,球会离开屏幕然后最终返回。就好像场景的边缘超出了iphone模拟器窗口的边缘。有人可以帮忙吗
我的场景有一堆矩形,物理体的大小与矩形相同。我喜欢将我所有的对象锚定到 CGPointZero,但是我注意到当我这样做时物理体仍然锚定在中间。换句话说,我的物理 body 的位置大约在视觉表示的左侧下
我想要的用法是这样的: 使用Tiled创建一个.tmx映射,该映射指定SpriteKit中将成为PhysicsBody对象的一堆对象的背景和起始位置 使用JSTileMap读取.tmx并显示它 在JS
我是一名优秀的程序员,十分优秀!