엔진/Cocos2d-x
cocos2d-x 3.x 멀티 해상도 대응하기 (multi resolution)
RPG만들기XP
2016. 4. 12. 15:43
코코스 초기 프로젝트를 생성하면 다음과 같은 코드가 기본으로 생성되어 있다.
// Set the design resolution glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::SHOW_ALL); Size frameSize = glview->getFrameSize(); // if the frame's height is larger than the height of medium size. if (frameSize.height > resolutionSize3.height) { director->setContentScaleFactor(MIN(designResolutionSize.height / resolutionSize4.height, designResolutionSize.width / resolutionSize4.width)); } // if the frame's height is larger than the height of small size. else if (frameSize.height > resolutionSize2.height) { director->setContentScaleFactor(MIN(designResolutionSize.height/ resolutionSize3.height, designResolutionSize.width/resolutionSize3.width)); } else if (frameSize.height > resolutionSize1.height) { director->setContentScaleFactor(MIN(designResolutionSize.height / resolutionSize2.height, designResolutionSize.width / resolutionSize2.width)); } // if the frame's height is smaller than the height of medium size. else { director->setContentScaleFactor(MIN(designResolutionSize.height / resolutionSize1.height, designResolutionSize.width / resolutionSize1.width)); }
이것 때문에 한참을 뻘짓하다가..(contentScaleFactor에 버그가 있는지, 1보다 큰 값을 넣어줘도 줄어들 때가 있는가 하면 작은 값을 넣어주면 원래 의도보다 너무 커지거나 하는 경우도 있다.)
얻은 해답은 위의 코드를 전부 삭제하는 것이다.
// Set the design resolution glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::SHOW_ALL); Size frameSize = glview->getFrameSize();
다만, 이 부분만 남겨 두면 된다.
setDesignResolutionSize 함수 하나만으로 (그리고 뒤에 넣어주는 ResolutionPolicy 인자만으로)
자동으로 모든 해상도에 맞춰서 자르고 늘리고 끼우고 다 해준다.
왜 아래의 필요없는 코드를 샘플 프로젝트에 포함시켜 두었는지는 의문.
갤럭시S6에서 잘 나오는 기념으로 인증샷