cocos2d-x 3.2 以及2.2.3 Director类分析

来源:互联网 发布:关键规则算法 编辑:程序博客网 时间:2024/06/05 15:19
// In this demo, we select resource according to the frame's height.    // If the resource size is different from design resolution size, you need to set contentScaleFactor.    // We use the ratio of resource's height to the height of design resolution,    // this can make sure that the resource's height could fit for the height of design resolution.    // if the frame's height is larger than the height of medium resource size, select large resource.
<span style="white-space:pre"></span>/*
<span style="white-space:pre"></span>首先资源又很多个版本1920*11080 到 960*640 一堆分辨率,这处没有处理16:9或者16:10的差异性,我们可以增加资源切边或直接拉伸挤压,影响不大,至少看起来能跑。当屏幕或者帧大于最高清资源的高度时,直接选择最高清。
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="white-space:pre"></span>*/</span>if (frameSize.height > mediumResource.size.height){        searchPath.push_back(largeResource.directory);        pDirector->setContentScaleFactor(MIN(largeResource.size.height/designResolutionSize.height, largeResource.size.width/designResolutionSize.width));}    // if the frame's height is larger than the height of small resource size, select medium resource.
<pre name="code" class="cpp"><span style="white-space:pre"></span>/*
<span></span>当屏幕或者帧小于最高清资源的高度且大于最小资源的设置,则选择<span style="font-family: Arial, Helvetica, sans-serif;">mediumResource,这个目录值得纠结一下,暂时没完成过完整的屏幕适配。</span>。
<span style="font-family: Arial, Helvetica, sans-serif;"><span></span>*/</span>
else if (frameSize.height > smallResource.size.height) { searchPath.push_back(mediumResource.directory); pDirector->setContentScaleFactor(MIN(mediumResource.size.height/designResolutionSize.height, mediumResource.size.width/designResolutionSize.width)); }
<pre name="code" class="cpp"><pre name="code" class="cpp"><span style="white-space:pre"></span>/*
<span></span>当屏幕或者帧小于最劣质资源的高度设置,则选择<span style="font-family: Arial, Helvetica, sans-serif;">smallResource</span><span style="font-family: Arial, Helvetica, sans-serif;">,这个目录值得纠结一下,暂时没完成过完整的屏幕适配。</span>。
<span style="font-family: Arial, Helvetica, sans-serif;"><span></span>*/</span>
// if the frame's height is smaller than the height of medium resource size, select small resource.else { searchPath.push_back(smallResource.directory); pDirector->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width)); } // set searching path CCFileUtils::sharedFileUtils()->setSearchPaths(searchPath);


也就是说,我们设置好资源的路径值和searchPath就可以解决之前遇到的屏幕适配问题。对于16:9和16:10的问题,我只能说iPhone都是16:9了,但是我们还是要去做切边的设置。都要了解切边具体操作。后续补。

0 0
原创粉丝点击