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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 01-21-2009, 03:42 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Lewisville, TX
Posts: 236
ukneeq is on a distinguished road
Send a message via AIM to ukneeq
Default Flicking to simulate a throw

Hello everyone. I was wondering if anyone could help with a question I have. I'm trying to simulate a "toss" when someone touches the ball and the flicks it. Could anyone suggest on how I use the flick gesture to simulate the toss? Basically use the flick for the speed of the throw. Any suggestions would be appreciated.

Thanks!
ukneeq is offline   Reply With Quote
Old 01-21-2009, 04:19 PM   #2 (permalink)
New Member
 
Join Date: Jan 2009
Location: New Zealand
Posts: 2
Newtz_2001 is on a distinguished road
Default

You should be able to use the touchesBegan and touchesEnded methods so long as your ball class inherits from UIResponder, which it should if it inherits from UIView or UIImageView.

In touchesBegan set an instance variable to the time the touch occurred and another to the location of the touch.

In touchesEnded set another use those instance variables to calculate how long the flick motion took and the distance of the flick and voila you have all the necessary components to calculate speed!
Newtz_2001 is offline   Reply With Quote
Old 01-21-2009, 04:27 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Lewisville, TX
Posts: 236
ukneeq is on a distinguished road
Send a message via AIM to ukneeq
Default

Thanks. Yea I started thinking about that. I do have it setup the way you described. I will just need to add the instance variables to keep track of the information.
ukneeq is offline   Reply With Quote
Old 01-22-2009, 11:19 AM   #4 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Lewisville, TX
Posts: 236
ukneeq is on a distinguished road
Send a message via AIM to ukneeq
Default

Quote:
Originally Posted by Newtz_2001 View Post
You should be able to use the touchesBegan and touchesEnded methods so long as your ball class inherits from UIResponder, which it should if it inherits from UIView or UIImageView.

In touchesBegan set an instance variable to the time the touch occurred and another to the location of the touch.

In touchesEnded set another use those instance variables to calculate how long the flick motion took and the distance of the flick and voila you have all the necessary components to calculate speed!
Ok, when doing this I noticed that the timestamp that the touch object gives is the last time the touch was moved or when it was started. So like if you move it and hold it still for like 3 seconds, it doesn't register the 3 seconds that it was held. Would I need to keep track of the actual time instead of the time interval?
ukneeq is offline   Reply With Quote
Old 01-22-2009, 01:08 PM   #5 (permalink)
New Member
 
Join Date: Jan 2009
Location: New Zealand
Posts: 2
Newtz_2001 is on a distinguished road
Default

I think I had a similar issue actually. Try using event.timestamp instead, that should give accurate timing
Newtz_2001 is offline   Reply With Quote
Old 02-25-2010, 06:35 PM   #6 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 3
blakeanator is on a distinguished road
Default Sample Code?

Can anyone provide any sample code for this?

Thanks,
Blake
blakeanator is offline   Reply With Quote
Old 02-27-2010, 09:07 AM   #7 (permalink)
Registered Member
 
herrvlad's Avatar
 
Join Date: Oct 2009
Posts: 82
herrvlad is on a distinguished road
Default

Would it be better to use touchesMoved rather than touchesEnded? Then the ball would move immediately after "throwing", not after the player lifts his finger.

Last edited by herrvlad; 02-27-2010 at 09:10 AM.
herrvlad is offline   Reply With Quote
Old 02-27-2010, 11:23 AM   #8 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 267
georgeburns is on a distinguished road
Default

Quote:
Originally Posted by ukneeq View Post
Ok, when doing this I noticed that the timestamp that the touch object gives is the last time the touch was moved or when it was started. So like if you move it and hold it still for like 3 seconds, it doesn't register the 3 seconds that it was held. Would I need to keep track of the actual time instead of the time interval?
Why don't you just use a fixed time interval and measure the distance at the touches ended from the touches ended touch to the touch just prior? Use that distance to determine the speed of the flick.
georgeburns is offline   Reply With Quote
Reply

Bookmarks

Tags
flicking, touches

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: 386
8 members and 378 guests
apatsufas, comicool, dansparrow, husthlj, LunarMoon, mer10, Murphy, pbart
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,677
Threads: 94,127
Posts: 402,916
Top Poster: BrianSlick (7,990)
Welcome to our newest member, husthlj
Powered by vBadvanced CMPS v3.1.0

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