{"action":"closed","issue":{"url":"https://api.github.com/repos/justmao945/justmao945.github.io/issues/59","labels_url":"https://api.github.com/repos/justmao945/justmao945.github.io/issues/59/labels{/name}","comments_url":"https://api.github.com/repos/justmao945/justmao945.github.io/issues/59/comments","events_url":"https://api.github.com/repos/justmao945/justmao945.github.io/issues/59/events","html_url":"https://github.com/justmao945/justmao945.github.io/issues/59","id":28638070,"number":59,"title":"cocos2dx multiple resolution","user":{"login":"justmao945","id":619331,"avatar_url":"https://avatars.githubusercontent.com/u/619331?v=3","gravatar_id":"","url":"https://api.github.com/users/justmao945","html_url":"https://github.com/justmao945","followers_url":"https://api.github.com/users/justmao945/followers","following_url":"https://api.github.com/users/justmao945/following{/other_user}","gists_url":"https://api.github.com/users/justmao945/gists{/gist_id}","starred_url":"https://api.github.com/users/justmao945/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justmao945/subscriptions","organizations_url":"https://api.github.com/users/justmao945/orgs","repos_url":"https://api.github.com/users/justmao945/repos","events_url":"https://api.github.com/users/justmao945/events{/privacy}","received_events_url":"https://api.github.com/users/justmao945/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/justmao945/justmao945.github.io/labels/programming","name":"programming","color":"f7c6c7"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2014-03-03T17:13:31Z","updated_at":"2015-05-15T05:16:47Z","closed_at":"2015-05-15T05:16:47Z","body":"Resolution\r\n-----\r\n这个resolution真是太容易迷惑了人了。。。源码中又没有什么说明。。。今天才在官网上找到[wiki][1]。。。好好研究研究记录记录。。。\r\n其实这个真是作死啊。。。各种屏幕各种分辨率。。。玩个蛋。。。\r\n想想Windows的游戏大部分总是会自动调整分辨率。。。这样就不用去应付不同分辨率，何况桌面的分辨率也不多。。。而移动端。。。\r\n\r\n总归是有resource resolution, design resolution, and screen resolution。\r\n为了适应不同的设备（不同的screen resolution），需要准备不同的resource resolution，但是为了编码方便，需要设定一个design resolution。\r\n\r\n视网膜。。。就是所谓的resource和screen的width * 2，height * 2，但是整个design resolution并不需要变？所以导致的结果是假如老的APP resource还是没有*4，那么就会出现“撸太多”的效果。。。自动blur了。。。\r\n\r\n* `EGLView::setDesignResolution(float width, float height, ResolutionPolicy)` 设定design的分辨率，即在编码过程中的参考分辨率，和“点”（在编码中使用的是Point，而不是pixel）坐标系相关。并且通过design resolution的设置，把转换后的图片重新scale到screen resolution上\r\n* `Director::setContentScaleFactor(float scale)`为缩放参数，指的是design resolution经过缩放，变成resource resolution的系数，`design resolution * scale factor = resource resolution`\r\n\r\n![resolutions](https://github.com/justmao945/justmao945.github.io/blob/master/static/blog/140304/cocos2dx-3resolutions-overview.png?raw=true)\r\n\r\n而scale factor有不同的计算方法，实际效果是不一样的，因为不同设备宽高比不是成比例的。。。有的胖有的瘦。。\r\n![content scale](https://github.com/justmao945/justmao945.github.io/blob/master/static/blog/140304/cocos2dx-contentScaleFactor.png?raw=true)\r\n\r\n看源码看了半天看不懂的神秘第三参数of `setDesignResolution`。。。\r\n![design resolution policy](https://github.com/justmao945/justmao945.github.io/blob/master/static/blog/140304/cocos2dx-setDesignResolutionSize.png?raw=true)\r\n\r\n![design resolution policy 2 ](https://github.com/justmao945/justmao945.github.io/blob/master/static/blog/140304/cocos2dx-setDesignResolutionSize-2.png?raw=true)\r\n\r\n\r\n* `EGLView::getFrameSize()`为实际设备的屏幕resolution，screen resolution\r\n* `Director::getWinSize()`为设定的design resolution\r\n* `Director::getVisibleSize()` 为可视区域的大小，即屏幕上看到的有效的区域大小\r\n* `Director::getVisibleOrigin()`为可视区域的原点在坐标系（design resolution）中的坐标，不一定为(0,0)，下图中320为design width，360为resource width，而270为screen width，所以只能看到270那一块的有效区域，经过换算，原点坐标在design resolution中为下图的值。。。邪恶的no boarder。。。另外fixed height和fixed width也是由坑的，就是前者会refine design resolution width，而后者是height，design resolution的width和height被切掉了，不过这样的好处是坐标得到了统一，可视的左下角一定是0,0。。。\r\n\r\n而multiple resolution的一切的关键就是固定和抓住9个点，3x3。。。\r\n\r\n![visible](https://github.com/justmao945/justmao945.github.io/blob/master/static/blog/140304/cocos2dx-visible.png?raw=true)\r\n\r\nco-ordinate\r\n-----\r\n还有当然是各种坐标系也是初学者容易困惑的。。。。[wiki][2]\r\n* Sprite的anchor默认是中心点(.5, .5)\r\n* 屏幕坐标系的原点在屏幕左下角，向右x正轴，向上y正轴，向屏幕外z正轴\r\n\r\n\r\n[1]: http://www.cocos2d-x.org/wiki/Detailed_explanation_of_Cocos2d-x_Multi-resolution_adaptation\r\n[2]: http://www.cocos2d-x.org/wiki/Coordinate_System"}}