PTM for box2d in cocos2d-x

Source: Internet
Author: User
The number of PTM_RATIO definitions when box2d is used in the cocos2d-x is related to the features of box2d itself. Someone else has explained it very clearly: www. raywenderlich. The following is an excerpt from the key part of the com28602intro-to-box2d-with-cocos2d-2-x-tutorial-bouncing-balls: # definePTM_RATIO32.0Thisis

The number of PTM_RATIO definitions when box2d is used in the cocos2d-x is related to the features of box2d itself. Someone else has explained it clearly: the http://www.raywenderlich.com/28602/intro-to-box2d-with-cocos2d-2-x-tutorial-bouncing-balls below is an excerpt from the key part: # define PTM_RATIO 32.0 This is

The number of PTM_RATIO definitions when box2d is used in the cocos2d-x is related to the features of box2d itself. What others have explained is clear:

Http://www.raywenderlich.com/28602/intro-to-box2d-with-cocos2d-2-x-tutorial-bouncing-balls


The following is an excerpt from the key part:

#define PTM_RATIO 32.0

This is defining a ratio of pixels to "meters ". when you specify where bodies are in Cocos2D, you give it a set of units. although you may consider using pixels, that wocould be a mistake. according to the Box2D manual, Box2D has been optimized to deal with units as small as 0.1 and as big as 10. so as far as length goes people generally tend to treat it as "meters" so 0.1 wocould be about teacup size and 10 wocould be about box size.

So we don't want to pass pixels in, because even small objects wocould be 60 × 60 pixels, way bigger than the values Box2D has been optimized. so we need to have a way to convert pixels to "meters", hence we can just define a ratio like the above. so if we had a 64 pixel object, we cocould pide it by PTM_RATIO to get 2 "meters" that Box2D can deal with for physics simulation purposes.

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.