Cocos2dThe problem of constant speed movement in development is described in this article,Cocos2dThere are CCMoveTo and CCMoveBy, but the speed parameters are time-limited. That is to say, the action is completed at the agreed time regardless of the distance.
However, if I want to control the speed, and the execution speed at any distance is the same. Are there such methods or classes?
Answer 1:
Speed x time = distance
Speed = distance/Time
Answer 2:
Define a speed by yourself, because you already know the location of Moveto, it means the distance is already there.
Time = distance/Speed
Answer 3:
Use a schedule such:
- -(Void) update :( cctime) dt
- {
- Xx = x + speed * dt;
- Yy = y + speed * dt;
- }
This dt is the time you want to move every time, which can be determined according to your own requirements.
Summary:Cocos2dThe content of the problem of constant speed movement in development is complete. I hope this article will help you!