Control the movement speed of objects in the game

Source: Internet
Author: User

Recently, we found in the Development of TD games that the moving objects in the game are quite different in the android simulator and the real machine.

For example, if the FPS on the simulator is 10 and the FPS on the real machine is 50, the object moving speed on the simulator will be very slow, but the real machine will run very fast.

How can we avoid the impact of machine performance on the moving speed of objects? In fact, it is also relatively simple, as long as you give the object a moving speed (with direction), and then record the time interval between the previous frame and the current frame, multiply by 0.001 to seconds.

The moving speed * time interval is used to determine the distance between each object to be moved. In this way, on machines with better performance, the time interval between each frame will be relatively short, and the moving speed will become smoother.

// Delta time interval public void Update (long delta) {// The moving distance from the X coordinate to centerx + = speed * (DIR) * Delta * 0.001 ;}

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.