【问题标题】:Cocos2d-x Game screen not fit in iPhone 4 with iOS 7Cocos2d-x 游戏屏幕不适合带有 iOS 7 的 iPhone 4
【发布时间】:2015-05-15 05:58:15
【问题描述】:

我是 Cocos2d-x 的新手,我在我的游戏中发现了奇怪的问题,我们正在所有运行良好的模拟器中进行测试。我们也在 iPhone 5 和 iPad 上测试我们的游戏,一切正常,但只在 iPhone 4 设备上出现问题。游戏画面显示小,顶部和右侧显示黑色区域,如下图所示:

我检查了它的所有默认图像大小和分辨率是否与苹果指南一样正确。

您能否建议我如何解决此问题。我不知道是否有任何与代码相关的问题或需要在 xcode 中进行更改。

以下是 iPhone 5 屏幕截图:


这是我的 appdelegate 代码:

bool AppDelegate::applicationDidFinishLaunching()
{
    wrapper->authenticateLocalPlayer();
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
    // turn on display FPS

    pDirector->setDisplayStats(false);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);
    CCSize Size = CCDirector::sharedDirector()->getWinSize();

    IPADX = Size.width/1024;
    IPADY = Size.height/768;

    if (Size.width==1024 || Size.width==2048){
        CCEGLView::sharedOpenGLView()->setDesignResolutionSize(1024, 768, kResolutionExactFit);
        SCALEX = 1.0f;
        SCALEY = 1.0f;
    }
    else
    {

            if (Size.width<568)
            {
                SCALEX = 960.0f/1024;
                SCALEY = 640.0f/768;

            }
            else
            {
                SCALEX = 1136.0f/1024;
                SCALEY = 640.0f/768;

            }
    }

        // create a scene. it's an autorelease object
    CCScene *pScene = HelloWorld::scene();

    // run
    pDirector->runWithScene(pScene);

    return true;
}

【问题讨论】:

  • 你能分享你的设置代码吗?
  • 您是否使用任何DesignResolutionSize 用于 glView ?看看 Appdelegate。
  • 是的,我使用了 setDesignResolutionSize 我编辑了我的问题,请检查@VijayMasiwal 和 iphonic
  • @NitinGohel 你没有为iPhone 4设置任何分辨率,应该是640x960
  • 你能否编辑我的代码并给出你的答案,我会暗示并让你知道@iphonic

标签: c++ ios iphone xcode cocos2d-x


【解决方案1】:

试试这个:

//设置设计分辨率

 Size designSize = Size(960, 640);
    if (Size.width==1024 || Size.width==2048){
        designSize = Size(1024, 768);
        SCALEX = 1.0f;
        SCALEY = 1.0f;
    }
    else
    {

        if (Size.width<568)
        {
            SCALEX = 960.0f/1024;
            SCALEY = 640.0f/768;

        }
        else
        {
            SCALEX = 1136.0f/1024;
            SCALEY = 640.0f/768;
            designSize = Size(1136, 640);
        }
    }

    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionExactFit);

    CCEGLView::sharedOpenGLView()->setContentScaleFactor(MAX(768/designSize.height,1024/designSize.width) );

【讨论】:

  • 我用你的代码解决了高问题,但右侧仍然显示黑色区域
  • 添加 scaleFact 后,Assertion failed: (m_eResolutionPolicy == kResolutionUnKnown), function setContentScaleFactor, 崩溃
  • @NitinGohel 你用的cocos2d-x是什么版本?
  • 试试这行Director::getInstance()-&gt;getOpenGLView()-&gt;setContentScaleFactor(MAX(768/designSize.height,1024/designSize.width) );
  • 它的 2.1.4 版本,我使用了你说的那一行,但应用程序崩溃了我在上面的评论断言中提到的失败
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-16
相关资源
最近更新 更多