「パーティクル」がユーザーのタッチに引き付けられる単純なゲームに取り組んでいます。TouchesMovedは、変更されていないタッチを無視して変更したタッチを返します。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSArray *touch = [touches allObjects];
for (numberOfTouches = 0; numberOfTouches < [touch count]; numberOfTouches++) {
lastTouches[numberOfTouches] = [((UITouch *)[touch objectAtIndex:numberOfTouches]) locationInView:self];
}
isTouching = YES;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSArray *touch = [touches allObjects];
for (numberOfTouches = 0; numberOfTouches < [touch count]; numberOfTouches++) {
lastTouches[numberOfTouches] = [((UITouch *)[touch objectAtIndex:numberOfTouches]) locationInView:self];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSArray *touch = [touches allObjects];
for (numberOfTouches = 0; numberOfTouches < [touch count]; numberOfTouches++) {
lastTouches[numberOfTouches] = [((UITouch *)[touch objectAtIndex:numberOfTouches]) locationInView:self];
}
if (!stickyFingers) {
isTouching = NO;
}
}
lastTouches
プログラムの別の部分は、粒子を移動させるために使用するCGPoint
の配列です。
私が抱えている問題は、3つの関数のどれかが呼び出されると、CGPointsとnumberOfTouchesの配列を上書きするということです。私はこれが問題になるとは思わなかったが、TouchesMovedは変更されたタッチを取得し、同じままであったタッチを取得しないことが分かった。その結果、あなたが指のうちの1つを動かすが他の指は動かさなければ、プログラムは動いていない指について忘れ、すべての粒子が動いている指に向かう。両方の指を動かすと、粒子は2本の指の間を移動します。
私は、あるものを更新している間に移動していないタッチを保持する必要があります。
何か提案がありますか?
'touchesCancelled:withEvent:'も実装することを忘れないでください。 –