【发布时间】:2014-10-24 16:03:08
【问题描述】:
我有一个游戏,其中圆形物体从屏幕底部弹出,我希望能够滑动它们以朝我滑动的方向轻弹它们。我的问题是,我不知道如何计算滑动的矢量/方向,以使圆形对象以适当的速度朝正确的方向轻弹。
我使用的静态向量“(5,5)”需要通过滑动速度和滑动方向来计算。另外,我需要确保一旦我第一次接触到物体,它就不再发生,以免双重撞击物体。这是我目前正在做的事情:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches) {
CGPoint location = [touch locationInNode:self];
SKNode* node = [self nodeAtPoint:location];
[node.physicsBody applyImpulse:CGVectorMake(5, 5) atPoint:location];
}
}
【问题讨论】:
标签: ios objective-c sprite-kit skphysicsbody