cocos2dx3.1.1版本的手机屏幕适配

前端之家收集整理的这篇文章主要介绍了cocos2dx3.1.1版本的手机屏幕适配前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.这是AppDelegate里的方法

bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLView::create("My Game");
glview->setFrameSize(800,480);//这里的屏幕大小是指的Windowns下的,对手机没有效果
director->setOpenGLView(glview);
}


// turn on display FPS
director->setDisplayStats(false);

//*****************关键点,在这里加上下面俩句话,就实现了手机的屏幕适配

auto designSize = Size(800,480);
glview->setDesignResolutionSize(designSize.width,designSize.height,ResolutionPolicy::SHOW_ALL);


//CCEGLView::sharedOpenGLView()->setDesignResolutionSize(800.0f,480.0f,kResolutionExactFit);
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0 / 60);


// create a scene. it's an autorelease object
auto scene = MyTouchEvent2::createScene();


// run
director->runWithScene(scene);


return true;
}

bool AppDelegate::applicationDidFinishLaunching() {

// initialize director auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { glview = GLView::create("My Game"); glview->setFrameSize(800,480); director->setOpenGLView(glview); } // turn on display FPS director->setDisplayStats(false); auto designSize = Size(800,480); glview->setDesignResolutionSize(designSize.width,ResolutionPolicy::SHOW_ALL); //CCEGLView::sharedOpenGLView()->setDesignResolutionSize(800.0f,kResolutionExactFit); // set FPS. the default value is 1.0/60 if you don't call this director->setAnimationInterval(1.0 / 60); // create a scene. it's an autorelease object auto scene = MyTouchEvent2::createScene(); // run director->runWithScene(scene); return true; }

猜你在找的Cocos2d-x相关文章