OK I’ve followed the instructions from [[Mechanism_of_loading_resources]] but my images are not loading. Here is some code.
static Resource smallResource = { cocos2d::CCSizeMake(480, 320), "480res" }; static Resource mediumResource = { cocos2d::CCSizeMake(1024, 768), "1024res" }; static Resource largeResource = { cocos2d::CCSizeMake(2048, 1536), "2048res" }; static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(480, 320);
bool AppDelegate::applicationDidFinishLaunching()
{
// initialize director
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
// Set up resolution independent guff
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder);
CCSize frameSize = pEGLView->getFrameSize();
// 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.
std::vector paths;
// if the frame's height is larger than the height of medium resource size, select large resource.
if (frameSize.height > mediumResource.size.height)
{
paths.push_back(largeResource.directory);
pDirector->setContentScaleFactor(largeResource.size.height/designResolutionSize.height);
}
// if the frame's height is larger than the height of small resource size, select medium resource.
else if (frameSize.height > smallResource.size.height)
{
paths.push_back(mediumResource.directory);
pDirector->setContentScaleFactor(mediumResource.size.height/designResolutionSize.height);
}
// if the frame's height is smaller than the height of medium resource size, select small resource.
else
{
paths.push_back(smallResource.directory);
pDirector->setContentScaleFactor(smallResource.size.height/designResolutionSize.height);
}
CCFileUtils::sharedFileUtils()->setSearchPaths(paths);
I have 3 directories, 480res, 1024res and 2048res residing under a folder called ‘images’. That folder has been added as a reference (Tried also without reference and it’s the same) to my project. The sprite creation is
@ CCSprite *circle = CCSprite::create(“images/circle.png”);@ and that is failing.
If I place the 480res etc under Resources, and set my search path to something like “Resources/480res” that fails also but it loads the 2048 resolution image sometimes and othertimes nothing.
Any ideas?