CCTOUCH movement speed detection

CCTOUCH movement speed detection
0.0 0


In cocos2dx-ios, i want to ask that :" how to get movement speed of (moved touch) ?


Use the general formula of speed : speed = distance/time

The distance is easy : it’s position - previousPosition.

For the time, you need to record the last time touchMoved was called for that touch, then compare it to current time.

The final formula is : (position - previousPosition) / (time - last time)


Btw. is there currently any method available to get the total time the app is running? I know this can be done by counting time in the update method but that is not very comfortable.


count running time doesn’t seem like the framework’s job…


Well, Marmalade SDK for example has this functionality and I think it could be useful in some situations (like mentioned touch gesture recognition). Afaik there is currently no function in cocos2d-x to get accurate time in milliseconds but probably it could be added very easily. Methods to retrieve accurate time vary depending on the platform so why not add something like this to the engine?