FWIW, I have the whole thing working, including switching out assets. Like you, I have different assets based on their format (for Windows, I’m allowing them to choose 16:9 small, 16:9 large, 21:9 small, 21:9 large, and fullscreen). I added this because I have an ultrawide monitor and so the iphonex assets look much better in full screen than the iphone5 ones.
I hope to add more high-res assets next year.
I had to fix my fonts by purging them and reloading them. Here’s my full method, and it works flawlessly during a game. I can even watch a play, switch to another resolution and watch the replay. I hope this helps! You’ll notice I do this only for Windows, because there’s no need to do it on iOS, and I’m not updating this on the Mac yet, that’ll come later.
void switchDisplayMode(int mode)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
bool fullscreen = false;
int desktopMode = -1; // invalid
// this lets me have a max size window
float openGlW = GetSystemMetrics(SM_CXSCREEN);
float openGlH = GetSystemMetrics(SM_CYSCREEN);
float availableHt = openGlH - ADJUST_Y(14) - ADJUST_Y(24);
float factor = availableHt / openGlH;
float w = 1920.0*factor;
float h = 1080.0*factor;
CCLOG("openGL width = %f, height = %f", openGlW, openGlH);
if (mode == kDesktopResFullscreen)
{
float ratio = openGlW / openGlH;
float ultrawide = 21.0/9.0;
CCLOG("ratio = %0.2f, ultrawide = %0.2f", ratio, ultrawide);
fullscreen = true;
w = 1920.0*factor;
h = 1080.0*factor;
desktopMode = DESKTOP_IPHONE5;
if (ratio >= ultrawide)
{
h = openGlH*factor;
w = 21.0*h/9.0;
desktopMode = DESKTOP_IPHONEX;
CCLOG("fullscreen, ultrawide");
}
else
CCLOG("fullscreen, NOT ultrawide");
}
else if (mode == kDesktopRes169Small || mode == kDesktopRes169Large)
{
// smaller window
if (mode == kDesktopRes169Small)
{
w = 1136.0*desktopFactor();
h = 640.0*desktopFactor();
}
desktopMode = DESKTOP_IPHONE5;
}
else if (mode == kDesktopRes219Small || mode == kDesktopRes219Large)
{
// smaller window
if (mode == kDesktopRes219Small)
{
w = 1218.0*desktopFactor();
h = 562.0*desktopFactor();
}
else
{
h = openGlH*factor;
w = 21.0*h/9.0;
}
desktopMode = DESKTOP_IPHONEX;
}
if (desktopMode != -1 || fullscreen)
{
desktopResolutionMode = desktopMode;
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
auto fileUtils = FileUtils::getInstance();
director->purgeCachedData();
// FontFNT::purgeCachedData();
// FontAtlasCache::purgeCachedData();
if (fullscreen)
{
dynamic_cast<GLViewImpl*>(cocos2d::Director::getInstance()->getOpenGLView())->setFullscreen();
}
else
{
dynamic_cast<GLViewImpl*>(cocos2d::Director::getInstance()->getOpenGLView())->setWindowed(w, h);
}
ResolutionPolicy resolutionPolicy = ResolutionPolicy::SHOW_ALL;
resolutionPolicy = ResolutionPolicy::EXACT_FIT;
// also fix the folders
std::vector<std::string> resDirOrders;
if (desktopMode == DESKTOP_IPHONE5)
{
resDirOrders.push_back("iphonehd5");
resDirOrders.push_back("iphonehd");
resDirOrders.push_back("iphone");
glview->setDesignResolutionSize(1136, 640, resolutionPolicy);
Director::getInstance()->setContentScaleFactor(1.0);
}
else
{
resDirOrders.push_back("iphonex");
resDirOrders.push_back("iphonehd5");
resDirOrders.push_back("iphonehd");
resDirOrders.push_back("iphone");
glview->setDesignResolutionSize(2436, 1125, resolutionPolicy);
Director::getInstance()->setContentScaleFactor(1.0);
}
fileUtils->setSearchResolutionsOrder(resDirOrders);
std::vector<std::string> searchPaths;
searchPaths.push_back("audio");
searchPaths.push_back("music");
searchPaths.push_back("files");
searchPaths.push_back("fonts");
searchPaths.push_back("backgrounds");
searchPaths.push_back("bmfonts");
searchPaths.push_back("images_animation");
searchPaths.push_back("images_players");
searchPaths.push_back("images_ui");
searchPaths.push_back("particles");
searchPaths.push_back("schedules");
searchPaths.push_back("player_names");
// myLog("setSearchPaths");
fileUtils->setSearchPaths(searchPaths);
// and reload all the spriteframes, in case I changed format
SpriteFrameCache::getInstance()->removeSpriteFramesFromFile("common_anim.plist");
SpriteFrameCache::getInstance()->removeSpriteFramesFromFile("ui_8888_trimmed.plist");
SpriteFrameCache::getInstance()->removeSpriteFramesFromFile("whiteset.plist");
SpriteFrameCache::getInstance()->removeSpriteFramesFromFile("whiteset.plist");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("common_anim.plist");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("colorset.plist", "dallas_color_jerseys.png");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("whiteset.plist", "dallas_white_jerseys.png");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("ui_8888_trimmed.plist");
// loadTeamsAndBindNames(game.team_idx[HOME_TM], game.team_idx[VISITING_TM]);
loadPlayerTextures(false);
}
// if (mode == kDesktopResFullscreen)
// addCloseButtonFullScreen();
#endif
}