在公司上班所做的一些笔记

来源:互联网 发布:怀孕食谱软件 编辑:程序博客网 时间:2024/05/16 09:22

1.关于屏幕幕适配

公司的项目基本上所有的屏幕大小都能完全适配好,首先的看了下它的AppDelegate.cpp文件,他是用的:

pEGLView->setDesignResolutionSize( 1280, 720,kResolutionNoBorder );

如果有的地方没适配好,就手动设置,它们的适配方法是:

// 自适应#define DESIGN_VIEWCCEGLView::sharedOpenGLView()->getDesignResolutionSize()#define VISIBLE_VIEWCCDirector::sharedDirector()->getVisibleSize()#define VISIBLE_ORIGINCCDirector::sharedDirector()->getVisibleOrigin()// 自适应位置,只有父窗口需要setvoid SetToVisiblePos( CCNode *node );float getWidthScale();float getHigthScale();void swCcbControl::SetToVisiblePos( CCNode *node ) {if (!node){  return ;} CCAssert( node != NULL, "" ); node->setPosition( node->getPosition().x * ( VISIBLE_VIEW.width / DESIGN_VIEW.width ) + VISIBLE_ORIGIN.x,node->getPosition().y * 
( VISIBLE_VIEW.height / DESIGN_VIEW.height ) + VISIBLE_ORIGIN.y );node->setScale(VISIBLE_VIEW.width / DESIGN_VIEW.width );}float swCcbControl::getHigthScale(){    return VISIBLE_VIEW.height / DESIGN_VIEW.height;}float swCcbControl::getWidthScale(){float yy = VISIBLE_ORIGIN.y;float xx = VISIBLE_ORIGIN.x;float vw = VISIBLE_VIEW.width;float dw = DESIGN_VIEW.width;float vh = VISIBLE_VIEW.height;float dh = DESIGN_VIEW.height;CCSize winsize = CCDirector::sharedDirector()->getWinSize();float winx = winsize.width;float winy = winsize.height;    return VISIBLE_VIEW.width / DESIGN_VIEW.width;}用法:mClose->setScaleY(swCcbControl::getWidthScale());

这样基本上就能适配所有屏幕了。

当屏幕休眠时或进入后台时,在AppDelegate.cpp中添加方法:这样就可以前后台切换了。

void AppDelegate::applicationDidEnterBackground()

{

     cocos2d::CCDirector::sharedDirector()->stopAnimation();
    // if you use SimpleAudioEngine, it must be pause    CocosDenshion::SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();}// this function will be called when the app is active againvoid AppDelegate::applicationWillEnterForeground() 
<span style="font-family: Arial, Helvetica, sans-serif;">{</span>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="white-space:pre"></span>cocos2d::CCDirector::sharedDirector()->startAnimation();</span>
    // if you use SimpleAudioEngine, it must resume here    CocosDenshion::SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();}

2.用到的一些宏:

// 判断vector取值是否越界#define VEC_VALUE( objPtr, vecName, pos )((objPtr->vecName.size() > pos ) ? objPtr->vecName[pos] : 0 )// 获得数组长度#define SW_ARRAY_LEN(arr)  ( sizeof(arr) / sizeof(arr[0]) )



0 0
原创粉丝点击