Cocos2dx 3.1.1 之 修改屏幕大小

来源:互联网 发布:全民k歌刷花软件 编辑:程序博客网 时间:2024/04/30 15:51

在cocos2dx 2.x版本中,修改屏幕大小的代码在main.cpp中:

 

#include "main.h"#include "AppDelegate.h"#include "CCEGLView.h"USING_NS_CC;int APIENTRY _tWinMain(HINSTANCE hInstance,                       HINSTANCE hPrevInstance,                       LPTSTR    lpCmdLine,                       int       nCmdShow){    UNREFERENCED_PARAMETER(hPrevInstance);    UNREFERENCED_PARAMETER(lpCmdLine);    // create the application instance    AppDelegate app;    CCEGLView* eglView = CCEGLView::sharedOpenGLView();    eglView->setViewName("Cocos2dx_JiKe_FlappyBird");    eglView->setFrameSize(640, 960);//在此处修改屏幕大小     return CCApplication::sharedApplication()->run();}</span>


 

 

到了cocos2dx 3.x版本,就改到了 AppDelegate.cpp中:

bool AppDelegate::applicationDidFinishLaunching() {    // initialize director    auto director = Director::getInstance();    auto glview = director->getOpenGLView();    if(!glview) {        glview = GLView::create("My Game");        director->setOpenGLView(glview);//此行是手动增加进去的,默认是没有的glview->setDesignResolutionSize(800, 600, ResolutionPolicy::SHOW_ALL);//设置屏幕    }    // 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);    // create a scene. it's an autorelease object    auto scene = HelloWorld::createScene();    // run    director->runWithScene(scene);    return true;}</span>


 

如果我们不进行手动修改屏幕大小,在CCGLView.cpp的create方法中会有屏幕大小默认的设置。当然我们也可以在此处进行修改

CCGLView.cpp

GLView* GLView::create(const std::string& viewName){    auto ret = new GLView;    if(ret && ret->initWithRect(viewName, Rect(0, 0, 960, 640), 1)) {        ret->autorelease();        return ret;    }    return nullptr;}//上下省略的许多代码


 

 

0 0
原创粉丝点击