AndEngine: Use of PIXEL_TO_METER_RATIO

泪湿孤枕 提交于 2019-12-23 16:07:29

问题


I am new to AndEngine. I have seen use of PIXEL_TO_METER_RATIO in lot of places but not able to understand when and how this constant is used. Can anyone guide to the right direction?


回答1:


Box2d, the underlying physics engine used by AndEngine, uses meters as standard units. PIXEL_TO_METER_RATIO describes how many pixels in AndEngine are equivalent to one meter in the physics engine. For example, if you get a position of the Body, it will be in meters. You would multiply it by the ratio to get a position on the Scene.




回答2:


the PTM_RATIO is defined because Box2D uses meters as standard units. for example, a screen of 480*320 pixels usually equals to a 15*10 square meters box2d world, if PTM_RATIO is defined as 32.


Box2D works with floating point numbers and tolerances have to be used to make Box2D perform well. These tolerances have been tuned to work well with meters-kilogram-second (MKS) units. In particular, Box2D has been tuned to work well with moving objects between 0.1 and 10 meters. So this means objects between soup cans and buses in size should work well. Static objects may be up to 50 meters big without too much trouble.


reference: http://www.box2d.org/manual.html



来源:https://stackoverflow.com/questions/11991622/andengine-use-of-pixel-to-meter-ratio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!