views:

140

answers:

2

Hey guys,

I'm a beginner when it comes to iPhone development and i've searched for the answer to this question and haven't found anything yet.

What i'm trying to do is allow the user to move an object without actually touching the object (they can touch anywhere on the screen) and as they move the object will go from where it was originally and move in the direction of the users movement but not jump to thier touch location and be covered up by their finger.

Any help you can provide would be phenomenal

Thank you in Advance,

BWC

A: 

You can subclass a UIView to track the touch movements by overriding the touchBegan:withEvent:, touchMoved:withEvent: and touchEnded:withEvent messages. In these messages, track the UITouch objects' locations (converted to points on the view by using the convertPoint:toView: message of the UIView you're subclassing) and calculate the difference of movement; then apply the same difference to your object, wherever it might be on the screen.

Aviad Ben Dov
Thank you for your response, I was trying to do everything in TouchesMoved and completely forgot about TouchesBegan...everything after that was just proper logic. You also opened my eyes to the ConvertPoint function which is one I wasn't aware up. Thank you again
BWC
A: 

I know this is old.... But here is a great tut doing this with Cocos2d and sprite animations. http://www.raywenderlich.com/1271/how-to-use-animations-and-sprite-sheets-in-cocos2d Derek

Derek