小弟是菜鸟 2016-06-09 02:55 采纳率: 0%
浏览 2221
已结题

cocos2d-x v3.9 屏幕适配问题

以前玩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;
}

结果就是,要么无法放大,要么拉伸过于明显.对了,还有我这个游戏是竖屏的.
希望大神能够解救一下.别再说什么百度了,我连谷歌都去了.可能是我太菜了,我依然还是没有能够解决这个问题.
希望大神能够帮我一下.
就这个问题,困扰我两天了,这个问题解决不了,下面的问题就无法进行.
在线等....

  • 写回答

2条回答

  • 普通网友 2016-10-05 16:06
    关注

    os2d-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);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B