COCOS2DX new game, very hot solution when the hand is running

Source: Internet
Author: User

COCOS2DX New development of the game, the hand is very hot, the need for friends can refer to.

COCOS2DX new research and development of the game, mobile phone running on the phone is very hot, and later listen to other project groups to share that can be resolved by reducing the frame of the problem, the original is cocos2dx default of 60, later modified to 30, the test found that mobile phone fever problem solved.

To modify the code:

AppDelegate.cpp

Set FPS. The default value is 1.0/60 if you don ' t call this

Pdirector->setanimationinterval (1.0/30);

And there is: Cocos2dxrenderer.java

//private static long Sanimationinterval = (long) (1.0/60 * cocos2dxrenderer.nanosecondspersecond);Private Static LongSanimationinterval = (Long) (1.0/ -*cocos2dxrenderer.nanosecondspersecond); @Override Public voidondrawframe (Final GL10 gl) {/** FPS controlling algorithm is not accurate, and it would slow down fps* on some devices. So comment FPS controlling code.*/FinalLongNowinnanoseconds =system.nanotime ();//should render a frame when ondrawframe () are called or there is a//"Ghost"Cocos2dxrenderer.nativerender (); finalLongAfterrendernano =system.nanotime ();//final long interval = afterrendernano-mlasttickinnanoseconds-cocos2dxrenderer.sanimationinterval;//afterrendernano-nowinnanoseconds;//nowinnanoseconds-this.mlasttickinnanoseconds;FinalLongInterval = Afterrendernano-nowinnanoseconds;//fps controllingif(Interval <cocos2dxrenderer.sanimationinterval) {//log.d ("Ondrawframe", "Cancel Frame" + interval + "/" +cocos2dxrenderer.sanimationinterval);Try {//because we render it before, so we should sleep twice time intervalThread.Sleep ((Cocos2dxrenderer.sanimationinterval-Interval)/cocos2dxrenderer.nanosecondspermicrosecond);} Catch(Final Exception e) {}}//this.mlasttickinnanoseconds = nowinnanoseconds;}

COCOS2DX new game, very hot solution when the hand is running

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.