I'm currently doing a project with a friend and one of the features we would like to implement is to be able to swipe the UIImages off the screen which would then register as a score as we have already implementing tapping the UIImages and it removes the UIImage and goes back to the start of its waypoint where the UIImage repeat and there is a maximum of 15 UIImages on the screen at any one time.
This whole project is coded on objective C and we've explored the possibility of using Cocatouch but our project supervisor has mentioned only to use objective C in the program.
Would anyone be so kind to be able to provide some code that would enable the UIImage to be swiped and it flies off the screen?(Like swiping an animal and it flies off the screen).
Thank you very much and I look forward to reading from you guys!
#define HORIZ_SWIPE_DRAG_MIN 12
#define VERT_SWIPE_DRAG_MAX 4
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
// startTouchPosition is an instance variable
startTouchPosition = [touch locationInView:self];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self];
// To be a swipe, direction of touch must be horizontal and long enough.
if (fabsf(startTouchPosition.x - currentTouchPosition.x) >= HORIZ_SWIPE_DRAG_MIN &&
fabsf(startTouchPosition.y - currentTouchPosition.y) <= VERT_SWIPE_DRAG_MAX)
{
// It appears to be a swipe.
if (startTouchPosition.x < currentTouchPosition.x)
[self myProcessRightSwipe:touches withEvent:event];
else
[self myProcessLeftSwipe:touches withEvent:event];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
startTouchPosition = 0.0;
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
startTouchPosition = 0.0;
}
To adapt this to your particular application, I would check to see that the swipe points occurred within the cgrect of your object (animal), if it does then move the object off screen, else, check other objects for intersecting points.
But it seems like i need more help, as the codes did call for the myProcessRightSwipe, I'm not very sure of how to make the images look like they are flying away, thus i do not know how to write the codes for this function.
But it seems like i need more help, as the codes did call for the myProcessRightSwipe, I'm not very sure of how to make the images look like they are flying away, thus i do not know how to write the codes for this function.
The 'myProcessRightSwipe' is a fictional method. Replace that one with your own method:
[self moveAnimal]; maybe
the the moveAnimal method may look like:
Code:
-(void) moveAnimal {
detect which animal was touched/swiped
make myAnimal.position move maybe with a separate timer method
}
It's tough to help much more, as I have no idea how many "animals" you are talking about, if they are stored in an array, or each named something different.