これを行う方法を考えています。ユーザーがスプライトをタップしてホールドしたときに、同じ y 値を維持しながら x 軸のみをドラッグできるようにするにはどうすればよいですか?
3 に答える
2
このチュートリアルに従ってください
http://www.raywenderlich.com/2343/how-to-drag-and-drop-sprites-with-cocos2d
y位置をタッチの位置に設定する代わりにスプライトの位置を設定する場合は、必要な固定値に設定するだけです。
于 2012-09-30T23:31:08.780 に答える
0
-(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;
}
次のようなスライダーを作成しました: https://github.com/Antem/Custom-Slider-xCode
于 2014-11-02T21:46:26.677 に答える
0
タッチを処理する場所:
if (CGRectContainsPoint(sprite.rect, touchLocation)){
sprite.position = ccp(touchLocation.x,sprite.position.y);
}
于 2012-10-02T10:29:08.457 に答える