Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-08-2010, 02:26 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 10
Default A little help on swiping UIImages

Hello there.

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!
Topnut is offline   Reply With Quote
Old 06-08-2010, 02:27 PM   #2 (permalink)
Indie Dev
 
hm50's Avatar
 
Join Date: May 2009
Location: South Bend, Indiana
Posts: 162
Default

From the Apple Programming Guide:

Code:
#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.
__________________
iPhone 3G

Support Indie Devs!! (that goes for newbs too!)

Apps:
Spell Blocks
See Read Say
iStatus
myVIP
myMVP
hm50 is offline   Reply With Quote
Old 06-08-2010, 11:14 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 10
Default

Thanks for your reply!

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.
Topnut is offline   Reply With Quote
Old 06-09-2010, 09:57 PM   #4 (permalink)
Indie Dev
 
hm50's Avatar
 
Join Date: May 2009
Location: South Bend, Indiana
Posts: 162
Default

Quote:
Originally Posted by Topnut View Post
Thanks for your reply!

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.
__________________
iPhone 3G

Support Indie Devs!! (that goes for newbs too!)

Apps:
Spell Blocks
See Read Say
iStatus
myVIP
myMVP

Last edited by hm50; 06-09-2010 at 10:00 PM.
hm50 is offline   Reply With Quote
Old 06-21-2010, 01:05 AM   #5 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 10
Default

Ok thank you very much, I would post over here if I am still stuck at that!
Topnut is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 242
24 members and 218 guests
ADY, AragornSG, bookesp, chillyh, dacapo, Dani77, Davey555, Dominus, dre, glenn_sayers, HemiMG, JasonR, karlam963, M.A.S., marshusensei, mer10, nobre84, Oral B, prchn4christ, Raggou, Rudy, spiderguy84, themathminister, viniciusdamone
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,765
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:24 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0