Я немного боролся с концепцией разрешения дизайна, когда пытался сделать фон моей игры подходящим для всех устройств iOS и всех устройств Android. Вот что я придумал:
//check if running on mobile device with native code or web browser
if (cc.sys.isNative)
{
//get the current search paths
var searchPaths = jsb.fileUtils.getSearchPaths();
//get the window size of the device
var winSize = cc.director.getWinSize();
//if the width matches the iPad retina
if(winSize.width == 2048){
//set the designResolutionSize to the dimmensions of the iPad Retina
cc.view.setDesignResolutionSize(2048, 1536, cc.ResolutionPolicy.EXACT_FIT);
//look in the extraLarge folder for assets
searchPaths.push("res/extraLarge/");
searchPaths.push("src");
isIpad = true;
isRetna = true;
}
//if the width matches the iPad
else if(winSize.width == 1024){
cc.view.setDesignResolutionSize(1024, 768, cc.ResolutionPolicy.EXACT_FIT);
searchPaths.push("res/large/");
searchPaths.push("src");
isIpad = true;
}
//if the width matches the iPhone 5 and higher
else if(winSize.width == 1136){
cc.view.setDesignResolutionSize(800, 450, cc.ResolutionPolicy.EXACT_FIT);
searchPaths.push("res/medium/");
searchPaths.push("src");
}
//if the width matches the iPhone 4
else if(winSize.width == 960){
cc.view.setDesignResolutionSize(960, 640, cc.ResolutionPolicy.EXACT_FIT);
searchPaths.push("res/small/");
searchPaths.push("src");
}
//anything else
else{
cc.view.setDesignResolutionSize(800, 450, cc.ResolutionPolicy.EXACT_FIT);
searchPaths.push("res/medium/");
searchPaths.push("src");
}
jsb.fileUtils.setSearchPaths(searchPaths);
}
//if not native code
else
{
cc.view.setDesignResolutionSize(800, 450, cc.ResolutionPolicy.SHOW_ALL);
cc.view.resizeWithBrowserSize(true);
}
Код прокомментирован, но подведем итог: проверьте, на каком устройстве iOS вы работаете, и установите соответственно designResolutionSize и путь поиска. Для всех остальных устройств выбирайте 800 x 450 и средний путь поиска. Для каждого из путей поиска у меня есть фоновый ресурс с теми же размерами, что и у designResolutionSize, и другие мои ресурсы масштабируются соответствующим образом.
Я решил проверить на устройствах iOS, потому что есть лишь небольшое количество устройств для проверки вместо нескольких разных устройств Android. Возможно, есть лучший способ сделать это, но это то, что работает для моей игры на iOS и устройствах Android, которые я и мои друзья тестировали.
person
Brandon M
schedule
26.03.2015