Here is my problem: I am trying to move a puzzle piece around the screen and then connect to the other piece if they are in close proximity. I have achieved this, though it is perhaps a little odd the way I did. My problem though is that once they have connected, I can't figure out how to move them as one image, instead of two separate entities开发者_JAVA技巧. I would really appreciate any help or suggestions. Here is a sample of what I have been doing:
- (void)touchesMovedNSSet *)touches withEventUIEvent *)event{
UITouch *touch = [touches anyObject];
[self dispatchTouchEvent:[touch view] toPosition:[touch locationInView:self.view]];
}
-(void)dispatchTouchEventUIView *)theView toPositionCGPoint)position{
if ((CGRectContainsPoint([picture frame], position))) {
picture.center = position;
}
if (CGRectContainsPoint([picture2 frame], position)) {
picture2.center = position;
}
}
What you could also do is set up an array with which pieces are connected, and when one of those pieces are selected, you know to move both pieces (or all connected pieces) at the same time now.
Once they've connected, are you allowing them to become disconnected again? If not, I'd just destroy the two original pieces and replace them with one object that shows the consolidated image. One beneficial side effect of this approach would be that the number of objects will fall over time as the user gets closer to finishing the puzzle.
精彩评论