>  기사  >  데이터 베이스  >  cocos2d-x中使用box2d时的PTM

cocos2d-x中使用box2d时的PTM

WBOY
WBOY원래의
2016-06-07 15:00:211025검색

cocos2d-x中使用box2d时的PTM_RATIO定义成多少和box2d本身的特性有关。别人已经解释的很清楚了: http://www.raywenderlich.com/28602/intro-to-box2d-with-cocos2d-2-x-tutorial-bouncing-balls 以下是其中重点部分的摘录: #define PTM_RATIO 32.0 This is

cocos2d-x中使用box2d时的PTM_RATIO定义成多少和box2d本身的特性有关。别人已经解释的很清楚了:

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


以下是其中重点部分的摘录:

<span>#define PTM_RATIO 32.0</span>

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 would 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 would be about teacup size and 10 would be about box size.

So we don’t want to pass pixels in, because even small objects would be 60×60 pixels, way bigger than the values Box2D has been optimized for. 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 could divide it by PTM_RATIO to get 2 “meters” that Box2D can deal with for physics simulation purposes.


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.