我正在使用cocos2d-x开发游戏.为了设置适合我的屏幕的背景图像,我使用了以下代码,但它拉伸图像请给出建议. bool AppDelegate::applicationDidFinishLaunching() { CCDirector *pDirector = CCDirector::sharedDir
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; }我通常做的是将图像缩放到屏幕尺寸比例.以下是一些帮助代码.
CCSprite * sprite = CCSprite::createWithSpriteFrameName(spriteName); sprite->setScaleX((winSize.width / sprite->getContentSize().width) * scaleXFactor); sprite->setScaleY((winSize.height / sprite->getContentSize().height) * scaleYFactor);
scaleXFactor和scaleYFactor是您想要的大小.如果您想要全屏,可以将其设置为1.