Search code examples
objective-cbackgroundsprite-kitswipe

How to move background using swipe gesture


I am a beginner programmer making a game for the AppStore on Xcode's sprite kit. The game takes place on a background wider than the screen (the height of the map is equal to the height of the screen but the width of my map is much larger than that of the screen), and I want the user to view the other parts of the map by swiping. Up until now I have used the touchesbegin,touchesmoved and touchesend methods to reposition the background map, but I wanted to give a shot at using UISwipeGestureRecognizer. I have just implemented the basics of this, but when I use something as follows:

- (void)handleSwipe:(UISwipeGestureRecognizer *)swipe
...
CGPoint touchLocation = [swipe locationInView:swipe.view]; 
touchLocation = [self convertPointFromView:touchLocation];
NSLog(@"Point A is %f,%f", touchLocation.x,touchLocation.y);
...

it will only take in the initial point where I began the swipe and regardless where I add a "CGPoint touchLocationEnd" in this method, it gives me the same position (the initial point).

What I would like to accomplish is to have the background map move as I move my pointer from one location to a second location (that is, for the point on the background map that I first click be dragged to a new position on the viewable screen). How can I accomplish this using UISwipeGestureRecgonizer? I'll be happy to go more in depth if this isn't clear


Solution

  • you use pan gesture instead of swipe gesture to move the background