My project uses localisation.
When i add images with "create group" option and do the following code - the images show up on simulator fine but not on the real device.
***Sample 1:***
MenuItemImage *leaderboard = MenuItemImage::create("btnLeaderboard.png", "btnLeaderboard.png", CC_CALLBACK_1(MenuLayer::onMenuItemClicked, this));
leaderboard->setTag(MenuItemTag::LEADERBOARD);
leaderboard->setPosition(-getContentSize().width/2 + (leaderboard->getContentSize().width * 0.75)/2, soundItem->getPositionY());
leaderboard->setScale(0.7);
items.pushBack(leaderboard);
menu *menu = Menu::createWithArray(items);
menu->setTag(212);
this->addChild(menu);
while if i add the images by "create folder references" option the images show up on both simulator & device but the localisation will be compromised and the code becomes like this :
***Sample 2:***
MenuItemImage *leaderboard = MenuItemImage::create("images/en.lproj/btnLeaderboard.png", "images/en.lproj/btnLeaderboard.png", CC_CALLBACK_1(MenuLayer::onMenuItemClicked, this));
leaderboard->setTag(MenuItemTag::LEADERBOARD);
leaderboard->setPosition(-getContentSize().width/2 + (leaderboard->getContentSize().width * 0.75)/2, soundItem->getPositionY());
leaderboard->setScale(0.7);
items.pushBack(leaderboard);
menu *menu = Menu::createWithArray(items);
menu->setTag(212);
this->addChild(menu);
but this isnt what i want.
Is there some setup in project that i'm missing causing images to not show up on device with the "sample 1" ? or if i'm doing something wrong with the code itself?
p.s. If it's possible to keep image localisation with "folder by reference" option as well then that would be nice too.
Folder references are the way to go.
You may want to consider adding a search path to the file utilities based on the current locale.
auto fileUtils = cocos2d::FileUtils::getInstance();
std::string localeImageDir = "en.lproj";
fileUtils->addSearchPath("images/" + locImageDir);
The above path will then be searched so:
auto explicit = Sprite::create("images/en.lproj/btnLeaderboard.png");
Becomes:
auto implicit = Sprite::create("btnLeaderboard.png");
The obvious limitation is that images must have identical names for each localisation.
If you need to change locale on the fly then you may want to use FileUtils::setSearchPaths() instead to override what was previously set.