Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Latest commit

 

History

History
106 lines (87 loc) · 4.1 KB

File metadata and controls

106 lines (87 loc) · 4.1 KB

#如何在低分辨的电脑上调试视网膜ipad的游戏

当调试手机游戏,有时移动设备的分辨率超过显示器的开发人员使用的分辨率。例如:Retina显示屏ipad拥有2048×1536的分辨率。

GLView:: setFrameZoomFactor功能诞生来解决这个问题。

##原则 EGLView:: setFrameZoomFactor重置游戏窗口的大小和投影乘以缩放因子。

在Win32:

void GLView::setFrameZoomFactor(float fZoomFactor)
    {
        m_fFrameZoomFactor = fZoomFactor;
        resize(m_obScreenSize.width * fZoomFactor, m_obScreenSize.height * fZoomFactor);
        centerWindow();
        Director::getInstance()->setProjection(Director::getInstance()->getProjection());
    }

GLView在Win32,Mac和Linux还重写两个函数,setViewPortInPointssetScissorInPoints

当投影复位,GLView::setViewPortInPoints将被调用。 的GLView::setViewPortInPoints的实施是从GLView::setViewPortInPoints不同。 所有的参数都是乘法与m_fFrameZoomFactor

    void GLView::setViewPortInPoints(float x , float y , float w , float h)
    {
        glViewport((GLint)(x * m_fScaleX * m_fFrameZoomFactor + m_obViewPortRect.origin.x * m_fFrameZoomFactor),
            (GLint)(y * m_fScaleY  * m_fFrameZoomFactor + m_obViewPortRect.origin.y * m_fFrameZoomFactor),
            (GLsizei)(w * m_fScaleX * m_fFrameZoomFactor),
            (GLsizei)(h * m_fScaleY * m_fFrameZoomFactor));
    }

    void GLView::setScissorInPoints(float x , float y , float w , float h)
    {
        glScissor((GLint)(x * m_fScaleX * m_fFrameZoomFactor + m_obViewPortRect.origin.x * m_fFrameZoomFactor),
                  (GLint)(y * m_fScaleY * m_fFrameZoomFactor + m_obViewPortRect.origin.y * m_fFrameZoomFactor),
                  (GLsizei)(w * m_fScaleX * m_fFrameZoomFactor),
                  (GLsizei)(h * m_fScaleY * m_fFrameZoomFactor));
    }

此外,虽然的Cocos2d-X得到系统的触摸事件,我们把x现在的位置是和ym_fFrameZoomFactor

    LRESULT EGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
    {
        BOOL bProcessed = FALSE;

        switch (message)
        {
        case WM_LBUTTONDOWN:
    .....
            if (m_pDelegate && MK_LBUTTON == wParam)
            {
                POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
                Point pt(point.x, point.y);
                pt.x /= m_fFrameZoomFactor;  // added this line
                pt.y /= m_fFrameZoomFactor;  // added this line
                Point tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
                if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp))
                {
                    m_bCaptured = true;
                    SetCapture(m_hWnd);
                    int id = 0;
                    handleTouchesBegin(1, &id, &pt.x, &pt.y);
                }
            }
            break;
    ................

##在哪里调用GLView:: setFrameZoomFactor? 此功能只能在平台相对应的代码调用。例如proj.win32/main.cppproj.mac/ AppController.mmproj.linux/ main.cpp。 只需添加一行代码就能使这个有用的功能。

例如,在Win32

    int APIENTRY _tWinMain(HINSTANCE hInstance,
                           HINSTANCE hPrevInstance,
                           LPTSTR    lpCmdLine,
                           int       nCmdShow)
    {
        UNREFERENCED_PARAMETER(hPrevInstance);
        UNREFERENCED_PARAMETER(lpCmdLine);

        // create the application instance
        AppDelegate app;
        GLView* eglView = Director::getInstance()->getOpenGLView();
        eglView->setFrameSize(2048, 1536);
        // The resolution of ipad3 is very large. In general, PC's resolution is smaller than it.
        // So we need to invoke 'setFrameZoomFactor'(only valid on desktop(win32, mac, linux)) to make the window smaller.
        eglView->setFrameZoomFactor(0.4f);
        return Application::sharedApplication()->run();
    }

结果:

img

现在,您就可以在低分辨率桌面上调试大分辨率游戏。期待你的加入。