cocos2dx 2.1.4 程序运行脉络解析1— win32版本的相关代码调用流程

我解析的是win32的代码:(比较之前版本的代码,我感觉引擎代码的布局要明确清晰多了,怪不得要换版本哈哈)


程序的入口点:


程序构造了一个AppDelegate对象,该对象继承自CCApplication,然后构造了CCEGLView对象,然后对CCEGLView进行了一些初始化等设置最后调用run方法进入游戏循环。


下面开始解析cocos2dx的重点类:CCEGLView

根据main函数调用流程 :
    CCEGLView* eglView = CCEGLView::sharedOpenGLView();
    eglView->setViewName("HelloCpp");
    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);


 CCEGLView::sharedOpenGLView():如果该类没有创建则创建并进行初始化相关操作:

下面是我根据功能划分分析的CCEGLView:

其中的setFrameZoomFactor函数实现需要重设投影矩阵,这一点暂时不明白,等到分析到那时再见知晓

void CCEGLView::setFrameZoomFactor(float fZoomFactor)
{
    m_fFrameZoomFactor = fZoomFactor;
    resize(m_obScreenSize.width * fZoomFactor, m_obScreenSize.height * fZoomFactor);
    centerWindow();

//运行机制已经分析完毕,重新设置投影是为了正确的将逻辑像素坐标的像素映射到屏幕中去,请参考第三节
//重新设置投影
    CCDirector::sharedDirector()->setProjection(CCDirector::sharedDirector()->getProjection());
}

CCEGLView win32 相对 CCEGLViewProtocol 多了一个 m_fFrameZoomFactor 属性是由于:(2dx的解释)

// 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.



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值