Game background stretched

Hi,
My game background looks different in my iPhone than in the Tablet. I’m using an Sprite to create it and I scaling it to 100% width and 100% height.

The problem is, I view it stretched (in height) in the tablet.
If i’ve this problem with others sprites i solve it scaling X and Y to the same amount (for example, based on the width), but i can’t scale the background based on the width because I need view it always in “full-screen”, so I should consider width and height.

How can I solve this problem?
I would like to view the game background perfect in iphone and tablet.

Scale9Sprite could solves my problem? I don’t know how it works.
Thanks.

Hi,

Read posts about multi resolution https://discuss.cocos2d-x.org/search?q=multi%20resolution

I read some suggestions, i tested some codes, but it didn’t solves my problem.
Have you a specific code for test it?

Anyway, my problem is the game background.
I can see correctly the other sprites, etc.
Is it really necessary to do something multi-resolution just for the background of the game? maybe I can solve it doing something specifically in this sprite

I tested this code and this suggestions
The stretching on the tablet occurs due to my scales :

bgGame->setScaleX(GameObject::getInstance()->getScaleValueSpriteX(bgGame, 1.0f));
bgGame->setScaleY(GameObject::getInstance()->getScaleValueSpriteY(bgGame, 1.0f));

Methods:

float GameObject::getScaleValueSpriteX(Sprite *s, float x)
{
    float visSizeX = Director::getInstance()->getVisibleSize().width; 
    float spriteWidth = s->getContentSize().width;
    float targetSmallSquareWidth = visSizeX * x;
    float scaleFactorX = targetSmallSquareWidth / spriteWidth;
    
    return scaleFactorX;
}

float GameObject::getScaleValueSpriteY(Sprite *s, float y)
{
    float visSizeY = Director::getInstance()->getVisibleSize().height; 
    float spriteHeight = s->getContentSize().height;
    float targetSmallSquareHeight = visSizeY * y;
    float scaleFactorY = targetSmallSquareHeight / spriteHeight;

    return scaleFactorY;
} 

But I need scale the game background always to 100% in x-y …

Ok I solved the problem. I will share it, maybe it’s useful for someone.
I created 3 folders inside Resources: SD, HD, and Retina. And I copied all sprites inside that folders, saved in different resolutions.

In AppDelegate I used the same code that cocos2d provides for manage multi resolutions. I only added the searchPaths for select the correct folder.

 // 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.0f / 60);

    std::vector<std::string> searchPaths;
    
    // Set the design resolution
    glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);

    auto frameSize = glview->getFrameSize();
    // if the frame's height is larger than the height of medium size.
    if (frameSize.height > mediumResolutionSize.height)
    {        
        director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
        searchPaths.push_back("RETINA");
    }
    // if the frame's height is larger than the height of small size.
    else if (frameSize.height > smallResolutionSize.height)
    {        
        director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
        searchPaths.push_back("HD");
    }
    // if the frame's height is smaller than the height of medium size.
    else
    {        
        director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
        searchPaths.push_back("SD");
    }

    cocos2d::FileUtils::getInstance()->setSearchPaths(searchPaths);
 
    register_all_packages();

That’s all.
Thanks.

My solution was to set this a bit different I can share those classes if they are helpful. It involves deciding what device and choosing an asset folder. Very much like what you did

Nice, please share it, maybe is better

Actually the only difference I am doing is I am doing more checking for what assets to show. I check for size and decide if it is a phone or a tablet and retina or not. I set bools for this that I can check.

It sounds like very similar to my code, anyway if you would like to share it, ur welcome.