以前玩cocos2d-x 是2.2.6版本,最近因为某些原因,下载了一个cocos2d-x v3.9.
在AppDelegate.app 里面有如下代码
//自动生成的
/*
static cocos2d::Size designResolutionSize = cocos2d::Size(480, 320);
static cocos2d::Size smallResolutionSize = cocos2d::Size(480, 320);
static cocos2d::Size mediumResolutionSize = cocos2d::Size(1024, 768);
static cocos2d::Size largeResolutionSize = cocos2d::Size(2048, 1536);*/
//我自己修改的
static cocos2d::Size designResolutionSize = cocos2d::Size(320, 480);
static cocos2d::Size smallResolutionSize = cocos2d::Size(640, 960);
static cocos2d::Size mediumResolutionSize = cocos2d::Size(720, 1280);
static cocos2d::Size largeResolutionSize = cocos2d::Size(1080, 1920);
bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if (!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
glview = GLViewImpl::createWithRect("plane", Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
#else
glview = GLViewImpl::create("plane");
#endif
director->setOpenGLView(glview);
}
// turn on display FPS
director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0 / 60);
// Set the design resolution
glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::FIXED_HEIGHT);
Size 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));
}
// 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));
}
// 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));
}
register_all_packages();
// create a scene. it's an autorelease object
auto scene = GameStart::createScene();
// run
director->runWithScene(scene);
return true;
}
在我的GameStart.cpp代码是这样的
bool GameStart::init()
{
if (!Layer::init())
return false;
//在cocos2d-x 2.2.6中,下面这段代码获取的是屏幕的大小
auto winSize=Director::getInstance()->getWinSize();
//添加背景图片
auto mainSprite = Sprite::create("images/background-main.png");
//设置位置为中心
mainSprite->setPosition(Vec2(winSize.width / 2, winSize.height / 2));
addChild(mainSprite);
//添加log.设置为中心位置
auto logoSprite = Sprite::create("images/chuhui-log.png");
logoSprite->setPosition(Vec2(winSize.width / 2, winSize.height / 2));
this->addChild(logoSprite);
//开启触摸
auto listener=EventListenerTouchOneByOne::create();
listener->onTouchBegan = [](Touch * touch, Event * event){
return true;
};
listener->onTouchEnded = [](Touch * touch, Event * event){
Director::getInstance()->replaceScene(MyDescription::createScene());
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
return true;
}
结果就是,要么无法放大,要么拉伸过于明显.对了,还有我这个游戏是竖屏的.
希望大神能够解救一下.别再说什么百度了,我连谷歌都去了.可能是我太菜了,我依然还是没有能够解决这个问题.
希望大神能够帮我一下.
就这个问题,困扰我两天了,这个问题解决不了,下面的问题就无法进行.
在线等....