I have a sprite in my iPhone game, how can make it so that that sprite moves to the location of my touch? It needs to transition there, not just switch immediately. My sprite is a CCSprite from cocos2d.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming you want to implement this using UIKit’s animation support (and your sprite is implemented as a view), this is one way of doing it.
on a touch event, get the location of the touch, and based on the current location of your sprite, determine how long it would take for your sprite to get there
inside an animation block, change the frame of your sprite view to the touch location, and also specify the duration and other options you want.
Apple’s ‘View Programming Guide’ will basically explains everything you need to know to take this approach.