Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

auto resizing in cocos2dx

I have made android build using cocos2dx for the device having size 480*320 and it works fine but when i put the same build in another android device having size 640*480 the scaling issue occurs....

I am using following code to re-size automatically, but it is not working:

AppDelegate app;
CCEGLView& eglView = CCEGLView::sharedOpenGLView();
eglView.setViewName("Hello Lua");
eglView.setFrameSize(480, 320);

// set the design resolution screen size, if you want to use Design Resoulution scaled to current screen, please uncomment next line.
// eglView.setDesignResolutionSize(480, 320);
like image 993
Ankush Avatar asked Jan 15 '23 23:01

Ankush


1 Answers

First of all, the code you have pasted is from main.cpp file which does not play a part when you compile the app for android or windows phone or ios. That file is for win32 project.

Now, for automatic scaling of app, the function in AppDelegate.cpp should set design resolution as well as policy. I use ExactFit policy because it stretches the app to fill the whole screen area and it works on Android , Windows, iOS everything (I have developed apps and tested) :

bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
    // turn on display FPS
    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(1200, 720, kResolutionExactFit);
    pDirector->setDisplayStats(false);

    pDirector->setAnimationInterval(1.0 / 60);

    CCScene *pScene = HelloWorld::scene();

    pDirector->runWithScene(pScene);
    return true;
}

You should also take a look at this Detailed explanation of multi-resolution support to understand it better.

like image 159
Wajahat Avatar answered Jan 23 '23 10:01

Wajahat