Hello,
I am working on an app and recently changed my resource folder to provide support for different devices (resolutions).
After I’ve done this, successfully on windows with Visual studio then I tested it on a Samsung phone via eclipse. It gives me no errors what so ever, but it seems to not find most of the resources as only a blackscreen is shown. The strange part is that it finds only one resource which is in the same folders as the others.
Here is my AppDelegate.cpp, applicationDidFinishLaunching:
bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
Size visibleSize = director->getVisibleSize();
glview = GLViewImpl::create("My Game");
director->setOpenGLView(glview);
// turn on display FPS
director->setDisplayStats(false);
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0 / 60);
auto fileUtils = FileUtils::getInstance( );
auto screenSize = glview->getFrameSize( );
std::vector<std::string> resDirOrders;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// check which assets the devices requires
if ( 2048 == screenSize.width || 2048 == screenSize.height ) // retina iPad
{
resDirOrders.push_back( "ipadhd" );
resDirOrders.push_back( "ipad" );
resDirOrders.push_back( "iphonehd5" );
resDirOrders.push_back( "iphonehd" );
resDirOrders.push_back( "iphone" );
glview->setDesignResolutionSize( 2048, 1536, ResolutionPolicy::NO_BORDER );
}
else if ( 1024 == screenSize.width || 1024 == screenSize.height ) // non retina iPad
{
resDirOrders.push_back( "ipad" );
resDirOrders.push_back( "iphonehd5" );
resDirOrders.push_back( "iphonehd" );
resDirOrders.push_back( "iphone" );
glview->setDesignResolutionSize( 1024, 768, ResolutionPolicy::NO_BORDER );
}
else if ( 1136 == screenSize.width || 1136 == screenSize.height ) // retina iPhone (5 and 5S)
{
resDirOrders.push_back("iphonehd5");
resDirOrders.push_back("iphonehd");
resDirOrders.push_back("iphone");
glview->setDesignResolutionSize( 1136, 640, ResolutionPolicy::NO_BORDER );
}
else if ( 960 == screenSize.width || 960 == screenSize.height ) // retina iPhone (4 and 4S)
{
resDirOrders.push_back( "iphonehd" );
resDirOrders.push_back( "iphone" );
glview->setDesignResolutionSize( 960, 640, ResolutionPolicy::NO_BORDER );
}
else // non retina iPhone and Android devices
{
if ( 1080 < screenSize.width && 1080 < screenSize.height ) // android devices that have a high resolution
{
resDirOrders.push_back( "iphonehd" );
resDirOrders.push_back( "iphone" );
glview->setDesignResolutionSize( 960, 640, ResolutionPolicy::NO_BORDER );
}
else // non retina iPhone and Android devices with lower resolutions
{
resDirOrders.push_back( "iphone" );
glview->setDesignResolutionSize( 480, 320, ResolutionPolicy::NO_BORDER );
}
}
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
resDirOrders.push_back( "ipad" );
resDirOrders.push_back( "iphonehd5" );
resDirOrders.push_back( "iphonehd" );
resDirOrders.push_back( "iphone" );
glview->setFrameSize( 1024, 768 );
glview->setDesignResolutionSize( 1024, 768, ResolutionPolicy::NO_BORDER );
#else
resDirOrders.push_back( "iphone" );
glview->setDesignResolutionSize( 480, 320, ResolutionPolicy::NO_BORDER );
#endif
fileUtils->setSearchPaths(resDirOrders);
// create a scene. it's an autorelease object
auto scene = MainMenu::createScene();
// run
director->runWithScene(scene);
return true;
}
I have a few of the same files in multiple folders ( but different resolution ) and all files in the lowest-resolution folder: iphone.
And here is the MainMenu.cpp file, which is the scene we create and run from AppDelegate:
#include "MainMenu.h"
#include "SimpleAudioEngine.h"
#include "GameLayer.h"
Scene* MainMenu::createScene()
{
// 'scene' is an autorelease object
//auto scene = Scene::create();
auto scene = Scene::createWithPhysics();
//disable for release:
//scene -> getPhysicsWorld() -> setDebugDrawMask( PhysicsWorld::DEBUGDRAW_ALL );
// 'layer' is an autorelease object
auto layer = MainMenu::create();
layer -> setPhyschisWorld( scene -> getPhysicsWorld() );
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
bool MainMenu::init()
{
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
auto origin = Director::getInstance()->getVisibleOrigin();
auto winSize = Director::getInstance()->getWinSize();
//particle test
auto m_emitter = CCParticleFire::createWithTotalParticles( 60 );
m_emitter->setPosition( origin.x + visibleSize.width * 1/6,
origin.y + visibleSize.height * 5/8 );
m_emitter->setGravity( Vec2( 0, 90 ) );
this->addChild( m_emitter, 10 );
auto m_emitter2 = CCParticleSmoke::createWithTotalParticles( 45 );
m_emitter2->setPosition( origin.x + visibleSize.width - (visibleSize.width * 1/6 ),
origin.y + visibleSize.height * 5/8 );
m_emitter2->setGravity( Vec2( 0, 90 ) );
this->addChild( m_emitter2, 10 );
//audio settings
auto audio = CocosDenshion::SimpleAudioEngine::getInstance();
if ( !audio->isBackgroundMusicPlaying() )
{
audio->setBackgroundMusicVolume( 0.5f );
audio->playBackgroundMusic( "sky-loop.wav", true );
}
//add background
cocos2d::Sprite* background = Sprite::create( "mainmenu2.png" );
background->setScaleX((visibleSize.width / background->getContentSize().width));
background->setScaleY((winSize.height / background->getContentSize().height));
background->setAnchorPoint( Vec2( origin.x, origin.y ) );
//background->setPosition( origin.x + visibleSize.width / 2, origin.y + visibleSize.height );
this->addChild( background, -1, -1 );
this->setZOrder( -10 );
//adds start game
cocos2d::Sprite* start_normal=Sprite::create( "startgame1.png" );
cocos2d::Sprite* start_pressed=Sprite::create( "startgame2.png" );
startgame_item = MenuItemSprite::create(start_normal, start_pressed, CC_CALLBACK_1(MainMenu::startgame, this));
startgame_item->setScaleX( (visibleSize.width / startgame_item->getBoundingBox().size.width) * 1/2 );
startgame_item->setScaleY( (visibleSize.height / startgame_item->getBoundingBox().size.height) * 1/8 );
startgame_item->setPosition( visibleSize.width/2 , visibleSize.height / 2 );
//adds settings
cocos2d::Sprite* settings_normal=Sprite::create( "settings1.png" );
cocos2d::Sprite* settings_pressed=Sprite::create( "settings2.png" );
settings_item = MenuItemSprite::create(settings_normal, settings_pressed, CC_CALLBACK_1(MainMenu::settings, this));
settings_item->setScaleX( (visibleSize.width / settings_item->getBoundingBox().size.width) * 1/2 );
settings_item->setScaleY( (visibleSize.height / settings_item->getBoundingBox().size.height) * 1/8 );
settings_item->setPosition( visibleSize.width/2 ,
startgame_item->getPosition().y - startgame_item->getBoundingBox().size.height / 2 - settings_item->getBoundingBox().size.height / 2 );
//adds testing
/*cocos2d::Sprite* testing_normal=Sprite::create( "testing1.png" );
cocos2d::Sprite* testing_pressed=Sprite::create( "testing1.png" );
test_item = MenuItemSprite::create(testing_normal, testing_pressed, CC_CALLBACK_1(MainMenu::testing, this));
test_item->setScaleX( (visibleSize.width / test_item->getBoundingBox().size.width) * 1/2 );
test_item->setScaleY( (visibleSize.height / test_item->getBoundingBox().size.height) * 1/8 );
test_item->setPosition( visibleSize.width/2 ,
settings_item->getPosition().y - settings_item->getBoundingBox().size.height / 2 - test_item->getBoundingBox().size.height / 2 );*/
//************* Menu ******************
auto menu = Menu::create(startgame_item, settings_item, NULL);
menu->setPosition(origin);
menu->setName("menu");
this->addChild(menu,3);
return true;
}
As I mentioned earlier, “sky-loop.wav” starts playing, but none of the images nor particles show up on the screen, nor any error messages in Eclipse.
Any help would be appreciated as I am stuck with headaches over this for a few days. If any other information is needed you can ask me or check my github: https://github.com/pjheden/jgame/tree/6eb099f002d09b5e3f705cf7d753d5a59c5eda02/JuliansGame/Classes
Thank you for you time.