i need to get the touch move velocity in cocos2d. any api for this?
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.
The most basic way of doing this is to do the following:
Of course,register a
CCLayerwith to be a touch event handler, and implement the touch begin, move and end functions.Create in your relevant class, 2
CGPointvariables to store theCURRENTandPREVIOUStouch positions. Also create 2CCTImestructures to store theCURRENTandPREVIOUSLYpolled times.Set up a schedule to update the current time (I’ve done this in the init of any relevant class.
i.e:
4 . at the start of touch begin, set both the previous and current variables to the current touch location using the following:
Then, in touch moved, set the PREVIOUS to the CURRENT, and set the CURRENT using the same line of code as above
Note that
CGPointsubtraction may not work as advertised above, you may have to subtract individual members and feed them into aCGPointfactory method.