When to use CC_CONTENT_SCALE_FACTOR()?

这一生的挚爱 提交于 2019-12-13 04:44:24

问题


I am a bit confused on when to use CC_CONTENT_SCALE_FACTOR() in my app. I use Box2D for collision detection, and I make a b2Body of vertices. Now should I divide each point only by the PTM_Ratio or by the PTM_Ratio multiplied by CC_CONTENT_SCALE_FACTOR()?

Should I be using CC_CONTENT_SCALE_FACTOR() anywhere in my app if I am not dealing with pixels? Should I only use CC_CONTENT_SCALE_FACTOR() for GLESDebugDraw like this?

_debugDraw = new GLESDebugDraw( ptmRatio * CC_CONTENT_SCALE_FACTOR()); ?

Thanks!


回答1:


The Box2D world doesn't care in how many pixels it is rendered in. Box2D is completely oblivious to screen resolution, therefore you don't and shouldn't scale any content whether you're on a Retina display device or not.

There's currently only one aspect where you might need CC_CONTENT_SCALE_FACTOR and that is when working with tilemaps. If I remember correctly, the tileset width and height properties are given in pixels, not points. Therefore you need to divide by CC_CONTENT_SCALE_FACTOR to get the correct size in points. Not sure why that's not done by cocos2d internally.




回答2:


all the positions, that are used by cocos2d are in points. In case of retina device one point is equal to two pixels. The situations when you need to use CC_CONTENT_SCALE_FACTOR() directly are rare and are not relatieve to the box2d. In case of using box2d you have only use ptmRatio to make translations between box2d's coordinates in meters and cocos2d's coordinates in points



来源:https://stackoverflow.com/questions/11200916/when-to-use-cc-content-scale-factor

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