Xcode 左右拖动精灵?
我想知道怎么做。如何使用户在点击并按住我的精灵时,可以仅在x轴上拖动它,保持相同的y值?遵循本教程Xcode 左右拖动精灵?,xcode,cocos2d-iphone,sprite,Xcode,Cocos2d Iphone,Sprite,我想知道怎么做。如何使用户在点击并按住我的精灵时,可以仅在x轴上拖动它,保持相同的y值?遵循本教程 当它设置精灵的位置而不是将y位置设置为触摸的位置时,只需将其设置为所需的固定值。在处理触摸时: if (CGRectContainsPoint(sprite.rect, touchLocation)){ sprite.position = ccp(touchLocation.x,sprite.position.y); } 我创建了如下滑块: -(void)touchesMoved:(
当它设置精灵的位置而不是将y位置设置为触摸的位置时,只需将其设置为所需的固定值。在处理触摸时:
if (CGRectContainsPoint(sprite.rect, touchLocation)){
sprite.position = ccp(touchLocation.x,sprite.position.y);
}
我创建了如下滑块:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *Drag = [[event allTouches] anyObject];
CGPoint CurrentPosition = [Drag locationInView:self.view];
CurrentPosition.x = Sprite.center.x;
Sprite.center = CurrentPosition;
}