【发布时间】:2014-05-02 23:59:00
【问题描述】:
我有一个 Box 节点,我只想通过向左或向右滑动来左右移动它。 下面代码的问题在于,一旦发生触摸,Box 就会明显跳到触摸的 x 位置,然后它会随着您的手指移动。
不错,但这不是我想要的效果,如果触摸发生(无论屏幕上的哪个位置),框都会保持在原位,并且只会相应地左右移动(- 或 x 的值触摸的位置)并且最初不要跳到手指的位置。所以 BoxNewPostion.postion.x 不应该真的等于 touchLocation.x
只是补充一点,如果我尝试,Box 会快速闪烁
CGPoint BoxNewPosition = CGPointMake(touchLocation.x - Box.postion.x, Box.position.y);
看起来好像延迟计算和减去 x 位置。
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
SKSpriteNode* Box = (SKSpriteNode*)[self childNodeWithName:@"BoxNode"];
CGPoint BoxNewPosition = CGPointMake(touchLocation.x, Box.position.y);
Box.position = BoxNewPosition;
}
【问题讨论】:
标签: objective-c ios7 sprite-kit