Analysis of constant speed movement in Cocos2d Development

Source: Internet
Author: User

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:

 
 
  1. -(Void) update :( cctime) dt
  2. {
  3. Xx = x + speed * dt;
  4. Yy = y + speed * dt;
  5. }

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.