I am developing a game using cocos2d-x
. For setting the background image fit to my screen I used the following code, but it stretch the image please give advice.
bool AppDelegate::applicationDidFinishLaunching() {
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector ->setOpenGLView(CCEGLView::sharedOpenGLView());
CCEGLView::sharedOpenGLView() ->setDesignResolutionSize(480, 320, kResolutionExactFit);
pDirector ->setDisplayStats(false);
pDirector ->setAnimationInterval(1.0 / 60);
CCScene *pScene = SplashScene::scene();
pDirector ->runWithScene(pScene);
return true;
}
What I usually do is that I scale the image to screen size ratio. Below is some code for help.
CCSprite * sprite = CCSprite::createWithSpriteFrameName(spriteName);
sprite->setScaleX((winSize.width / sprite->getContentSize().width) * scaleXFactor);
sprite->setScaleY((winSize.height / sprite->getContentSize().height) * scaleYFactor);
scaleXFactor and scaleYFactor is the size that you want. if you want it to be full screen you can set it to 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With