Auto scale screen size problem

how can i auto fit the screen size?
i am using cocs2d-2.0-rc0a-x-2.2.

i have trying the code

bool AppDelegate::initInstance()
{
bool bRet = false;
do
{
#if (CC_TARGET_PLATFORM CC_PLATFORM_WIN32)

    // Initialize OpenGLView instance, that release by CCDirector when application terminate.
    // The HelloWorld is designed as HVGA.
    CCEGLView \* pMainWnd = new CCEGLView();
    CC\_BREAK\_IF(! pMainWnd
        || ! pMainWnd-\>Create(TEXT("cocos2d: Hello World"), 480, 320));

#define WVGA

#if defined(QVGA)
#define ACTURAL_SCREEN_WIDTH 320
#define ACTURAL_SCREEN_HEIGHT 240
#elif defined(HVGA)
#define ACTURAL_SCREEN_WIDTH 480
#define ACTURAL_SCREEN_HEIGHT 320
#elif defined(WVGA)
#define ACTURAL_SCREEN_WIDTH 800
#define ACTURAL_SCREEN_HEIGHT 480
#else
#define ACTURAL_SCREEN_WIDTH 854
#define ACTURAL_SCREEN_HEIGHT 480
#endif
pMainWnd->setScreenScale(max(ACTURAL_SCREEN_WIDTH / 480.0, ACTURAL_SCREEN_HEIGHT / 320.0));
pMainWnd->resize(ACTURAL_SCREEN_WIDTH, ACTURAL_SCREEN_HEIGHT);
pMainWnd->centerWindow();

#endif // CC_PLATFORM_WIN32

#if (CC_TARGET_PLATFORM CC_PLATFORM_IOS)

// OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here.

#endif // CC_PLATFORM_IOS

#if (CC_TARGET_PLATFORM CC_PLATFORM_ANDROID)

    // OpenGLView initialized in HelloWorld/android/jni/helloworld/main.cpp
    // the default setting is to create a fullscreen view
    // if you want to use auto-scale, please enable view-\>create(320,480) in main.cpp

#endif // CC_PLATFORM_ANDROID

#if (CC_TARGET_PLATFORM CC_PLATFORM_WOPHONE)

// Initialize OpenGLView instance, that release by CCDirector when application terminate.
// The HelloWorld is designed as HVGA.
CCEGLView* pMainWnd = new CCEGLView(this);
CC_BREAK_IF(! pMainWnd || ! pMainWnd->Create(320,480, WM_WINDOW_ROTATE_MODE_CW));

#ifndef TRANZDA_VM
// on wophone emulator, we copy resources files to Work7/NEWPLUS/TDA_DATA/Data/ folder instead of zip file
cocos2d::CCFileUtils::setResource(“HelloWorld.zip”);
#endif

#endif // CC_PLATFORM_WOPHONE

#if (CC_TARGET_PLATFORM == CC_PLATFORM_AIRPLAY)
// MaxAksenov said it’s NOT a very elegant solution. I agree, haha
CCDirector::sharedDirector()>setDeviceOrientation;
#endif
bRet = true;
} while ;
return bRet;
}
But the
pMainWnd
>setScreenScale(max(ACTURAL_SCREEN_WIDTH / 480.0, ACTURAL_SCREEN_HEIGHT / 320.0));
is error.
The setScreenSacle function is not member in the CCEGLView.h.
it is the version problem?

CCApplication::initInstance method have been removed in 2.0.
The auto scale codes have been placed at platform folders, e.g. proj.win32/main.cpp, proj.android/jni/helloworld/main.cpp

On WIN32:

int APIENTRY _tWinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPTSTR    lpCmdLine,
                       int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // create the application instance
    AppDelegate app;
    CCEGLView& eglView = CCEGLView::sharedOpenGLView();
    eglView.setViewName("Hello World");
    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);
    return CCApplication::sharedApplication().run();
}

On Android:

void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv*  env, jobject thiz, jint w, jint h)
{
    if (!CCDirector::sharedDirector()->getOpenGLView())
    {
        CCEGLView *view = &CCEGLView::sharedOpenGLView();
        view->setFrameSize(w, h);
        // *set the design resolution screen size, if you want to use Design Resoulution scaled to current screen, please uncomment next line.*
        // view->setDesignResolutionSize(480, 320);

        AppDelegate *pAppDelegate = new AppDelegate();
        CCApplication::sharedApplication().run();
    }
    else
    {
        ccDrawInit();
        ccGLInvalidateStateCache();

        CCShaderCache::sharedShaderCache()->reloadDefaultShaders();
        CCTextureCache::reloadAllTextures();
        CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
        CCDirector::sharedDirector()->setGLDefaultValues(); 
    }
}

i have following your code and added in the main.cpp
but it have some error message.

The error.png is the print screen.

Please review my reply on the second floor.

i am already add the code in the win32 and the android platform.
On the win32 platform,
i have the code to check and scale the background image to fit the screen size and the image position is right.

@ size = CCDirector::sharedDirector()>getWinSize;
Level1_pSprite = CCSprite::spriteWithFile;
Level1_pSprite
>setScaleX(size.width/Level1_pSprite~~>getContentSize.width);
Level1_pSprite~~>setScaleY(size.height/Level1_pSprite~~>getContentSize.height);
Level1_pSprite~~>setPosition( ccp(240, 160));

this->addChild(Level1_pSprite, 0);@

on the android platform,
The background image is fit the screen size but the image position is not right.
The following image is the android platform screen capture.

What’s the size of Level1_bg.png? Why did you scale it manually?

The image size is 553x417.
The size need 480x320 and the position set to 0,0 or 240,160?

OK, it’s really strange, could you upload a demo based on HelloWorld for us to analyse ?

CCMenuItemImage* Level1_photo1;
CCMenuItemImage* Level1_photo2;
CCMenuItemImage* Level1_photo3;
bool HelloWorld::Level1()
{
size = CCDirector::sharedDirector()>getWinSize;
Level1_pSprite = CCSprite::spriteWithFile;
Level1_pSprite
>setScaleX(size.width/Level1_pSprite~~>getContentSize.width);
Level1_pSprite~~>setScaleY(size.height/Level1_pSprite~~>getContentSize.height);
Level1_pSprite~~>setPosition(ccp(size.width/2, size.height/2));
this~~>addChild;
Level1_photo1 = CCMenuItemImage::itemWithNormalImage );
Level1_photo1~~>setScaleX(size.width/Level1_pSprite~~>getContentSize.width);
Level1_photo1~~>setScaleY(size.height/Level1_pSprite~~>getContentSize.height);
Level1_photo1~~>setPosition( ccp(190, 175));

Level1_photo2 = CCMenuItemImage::itemWithNormalImage(
“Level1_1.png”,
“Level1_1.png”,
this,
menu_selector(HelloWorld::Level1_photo2CallBack) );
Level1_photo2~~>setScaleX.width);
Level1_photo2~~>setScaleY(size.height/Level1_pSprite~~>getContentSize.height);
Level1_photo2~~>setPosition( ccp(300, 200));

Level1_photo3 = CCMenuItemImage::itemWithNormalImage(
“Level1_1.png”,
“Level1_1.png”,
this,
menu_selector(HelloWorld::Level1_photo3CallBack) );
Level1_photo3~~>setScaleX.width);
Level1_photo3~~>setScaleY(size.height/Level1_pSprite~~>getContentSize.height);
Level1_photo3~~>setPosition( ccp(410, 50));

CCMenu* Level1_Menu = CCMenu::menuWithItems(Level1_photo1, Level1_photo2, Level1_photo3, NULL);
Level1_Menu~~>setPosition;
this~~>addChild(Level1_Menu, 0);
return true;
}

void HelloWorld::Level1_photo1CallBack(CCObject* pSender)
{
CCFiniteTimeAction* actionMove = CCMoveTo::actionWithDuration( (ccTime)0.5, ccp(240, 160) );
CCFiniteTimeAction* actionMoveDone =
CCCallFuncN::actionWithTarget( this,
callfuncN_selector(HelloWorld::Level1_photo1_spriteMoveFinished));
Level1_photo1~~>runAction );
}
void HelloWorld::Level1_photo2CallBack
{
CCFiniteTimeAction* actionMove = CCMoveTo::actionWithDuration0.5, ccp );
CCFiniteTimeAction* actionMoveDone =
CCCallFuncN::actionWithTarget);
Level1_photo2~~>runAction( CCSequence::actions(actionMove,
actionMoveDone, NULL) );
}

void HelloWorld::Level1_photo3CallBack(CCObject* pSender)
{
CCFiniteTimeAction* actionMove = CCMoveTo::actionWithDuration( (ccTime)0.5, ccp(240, 160) );
CCFiniteTimeAction* actionMoveDone =
CCCallFuncN::actionWithTarget( this,
callfuncN_selector(HelloWorld::Level1_photo3_spriteMoveFinished));
Level1_photo3->runAction( CCSequence::actions(actionMove,
actionMoveDone, NULL) );
}

Could you make a package including whole project?
wing lau wrote:

CCMenuItemImage* Level1_photo1;
CCMenuItemImage* Level1_photo2;
CCMenuItemImage* Level1_photo3;
bool HelloWorld::Level1()
{
size = CCDirector::sharedDirector()>getWinSize;
>
Level1_pSprite = CCSprite::spriteWithFile;
Level1_pSprite
>setScaleX(size.width/Level1_pSprite~~>getContentSize.width);
Level1_pSprite~~>setScaleY(size.height/Level1_pSprite~~>getContentSize.height);
Level1_pSprite~~>setPosition(ccp(size.width/2, size.height/2));
this~~>addChild;
>
Level1_photo1 = CCMenuItemImage::itemWithNormalImage );
Level1_photo1~~>setScaleX(size.width/Level1_pSprite~~>getContentSize.width);
Level1_photo1~~>setScaleY(size.height/Level1_pSprite~~>getContentSize.height);
Level1_photo1~~>setPosition( ccp(190, 175));
>
Level1_photo2 = CCMenuItemImage::itemWithNormalImage(
“Level1_1.png”,
“Level1_1.png”,
this,
menu_selector(HelloWorld::Level1_photo2CallBack) );
Level1_photo2~~>setScaleX.width);
Level1_photo2~~>setScaleY(size.height/Level1_pSprite~~>getContentSize.height);
Level1_photo2~~>setPosition( ccp(300, 200));
>
Level1_photo3 = CCMenuItemImage::itemWithNormalImage(
“Level1_1.png”,
“Level1_1.png”,
this,
menu_selector(HelloWorld::Level1_photo3CallBack) );
Level1_photo3~~>setScaleX.width);
Level1_photo3~~>setScaleY(size.height/Level1_pSprite~~>getContentSize.height);
Level1_photo3~~>setPosition( ccp(410, 50));
>
CCMenu* Level1_Menu = CCMenu::menuWithItems(Level1_photo1, Level1_photo2, Level1_photo3, NULL);
Level1_Menu~~>setPosition;
>
this~~>addChild(Level1_Menu, 0);
return true;
}
>
>
void HelloWorld::Level1_photo1CallBack(CCObject* pSender)
{
CCFiniteTimeAction* actionMove = CCMoveTo::actionWithDuration( (ccTime)0.5, ccp(240, 160) );
CCFiniteTimeAction* actionMoveDone =
CCCallFuncN::actionWithTarget( this,
callfuncN_selector(HelloWorld::Level1_photo1_spriteMoveFinished));
Level1_photo1~~>runAction );
}
>
void HelloWorld::Level1_photo2CallBack
{
CCFiniteTimeAction* actionMove = CCMoveTo::actionWithDuration0.5, ccp );
CCFiniteTimeAction* actionMoveDone =
CCCallFuncN::actionWithTarget);
Level1_photo2~~>runAction( CCSequence::actions(actionMove,
actionMoveDone, NULL) );
}
>
void HelloWorld::Level1_photo3CallBack(CCObject* pSender)
{
CCFiniteTimeAction* actionMove = CCMoveTo::actionWithDuration( (ccTime)0.5, ccp(240, 160) );
CCFiniteTimeAction* actionMoveDone =
CCCallFuncN::actionWithTarget( this,
callfuncN_selector(HelloWorld::Level1_photo3_spriteMoveFinished));
Level1_photo3->runAction( CCSequence::actions(actionMove,
actionMoveDone, NULL) );
}

http://www.sendspace.com/file/7oqogf

I’m sorry, I don’t know how to download it from ‘SendSpace’. When I click download, it just links to a wrong page of ad. —_-!

i can’t to upload the file when i using the forum upload function.
I am already send the email to you with the my project.

Hi, wing lau,
I have reviewed your codes, and found a lot of ‘setScale’. Why not use ‘setDesignResolutionSize’ to achieve scale instead of scaling manually?

wing lau wrote:

i can’t to upload the file when i using the forum upload function.
I am already send the email to you with the my project.

It’s too complex if you use this way!

i have try the setDesignResolutionSize to set the scale function.
but the image result is not scale.

On windows, you should setFrameSize before setDesignResolutionSize, setFrameSize indicates the window size.
So if your android device screen size is 800*480, debug it on win32 by using the codes bellow:

    AppDelegate app;
    CCEGLView& eglView = CCEGLView::sharedOpenGLView();
    eglView.setViewName("Hello World");
    eglView.setFrameSize(800, 480); // this line is to change the window size.

    // *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);
    return CCApplication::sharedApplication().run();

i have used the code in the project.
My android device screen size is 800*480(gs2).

AppDelegate app;
CCEGLView& eglView = CCEGLView::sharedOpenGLView();
eglView.setViewName(“Hello World”);
eglView.setFrameSize(800, 480);
//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);
return CCApplication::sharedApplication().run();

It is my image code.

Level9_pSprite = CCSprite::spriteWithFile(“Level9_bg.png”);
Level9_pSprite~~>setPosition);
this~~>addChild(Level9_pSprite, 0);

You can see the image about windowOS.png and androidOS.png

android os image

Is there anyways we can just talk pixels only. For all devices. It doesn’t matter to our game if the devices sees a little more or little Less of the map. We a top down racing game and we really just need to build with pixels only

Any advice much appreciated