2012年10月2日火曜日

【cocos2d-x】setDesignResolutionSizeのパラメーターによる表示の違い。

OpenGLViewにDesignResolutionSizeというパラメータがあるので、 AppDelegate.cppのapplicationDidFinishLaunchingでセットしてあげると勝手にサイズを調整してくれるのでとても便利です。
bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());

    // ここに書く

    // turn on display FPS
    pDirector->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);

    // create a scene. it's an autorelease object
    CCScene *pScene = HelloWorld::scene();

    // run
    pDirector->runWithScene(pScene);

    return true;
}

ipadシミュレーター(768 * 1024)でテスト。

Default.png(320*480)を画面中央に表示してます。

setDesignResolutionSizeなし。

画像サイズそのままで描画されます。

kResolutionShowAllの場合。

縦横比を保って画面いっぱいに表示されます。余白は黒く表示。
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(320, 480, kResolutionShowAll);

kResolutionExactFitの場合。

縦横比を保たずに余白が全て埋まります。
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(320, 480, kResolutionExactFit);

kResolutionNoBorderの場合。

縦横比を保ったまま余白を埋めるのではみ出ます。
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(320, 480, kResolutionNoBorder);

使い分け方は

・kResolutionShowAllは画像サイズを固定したい時。余白は仕方がないとする。

・kResolutionExactFitは多少潰れるなり伸びるなりしても余白を埋めたい時。

・kResolutionNoBorderは画面中央にコンテンツがよっていて多少はみ出ても問題ない時。

みたいな感じでしょうか。

特にandroid端末はサイズも縦横比もバラバラなのでこれで一括管理するのが楽ちんですね。

0 件のコメント: