在SpriteKit中使用touchesMoved旋转奖品轮 [英] Spinning a prize wheel with touchesMoved in SpriteKit

查看:168
本文介绍了在SpriteKit中使用touchesMoved旋转奖品轮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用applyAngularImpulse而不是以指数方式提高车轮的速度?

理想情况下,我想让车轮跟随我的手指,但设置 node.zRotation + = atan2f(y2-y1,x2-x1)旋转我的轮子失去控制。这就是我所确定的,但感觉非常不稳定:

is it possible to use applyAngularImpulse but not exponentially increase the speed of the wheel?
Ideally I'd like to have the wheel follow my finger, but setting node.zRotation += atan2f(y2-y1, x2-x1) spins my wheel out of control. here's what i settled on, but it feels pretty wonky:

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

  UITouch *touch = [touches anyObject];
  SKNode *node = [self nodeAtPoint:location];

  CGPoint positionInScene = [touch locationInNode:self];
  CGPoint previousPosition = [touch previousLocationInNode:self];

  [node.physicsBody applyAngularImpulse:(previousPosition.x - positionInScene.x) * 0.1];
  node.physicsBody.angularDamping = 1;
}

场景: https://dl.dropboxusercontent.com/s/gexfburjm1coude/Screen %20Shot%202014-10-21%20at%2010.30.31%20 PM.png?dl = 0

推荐答案

应用你的冲动后:

[node.physicsBody applyAngularImpulse:theImpulse];

只需将角速度钳制到最大速度,其最大速度取决于您想要允许车轮的速度旋转:

Simply clamp the angular velocity to a maximum speed whose value depends on how fast you want to allow the wheel to spin:

const CGFloat maxAngularVelocity = 2.5;
node.physicsBody.angularVelocity = MIN(node.physicsBody.angularVelocity, maxAngularVelocity);

这篇关于在SpriteKit中使用touchesMoved旋转奖品轮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆