Home  >  Article  >  Database  >  Cocos2dx屏幕匹配

Cocos2dx屏幕匹配

WBOY
WBOYOriginal
2016-06-07 15:09:38989browse

思路 1 )首先是横屏改为竖屏,因为 android 项目的 screenOrientation 默认为横屏; 2 )设置自适应屏。 【二】:横竖换屏 1 、 Cocos2d-x2.x 版 ,打开 main.cpp 文件 找到 eglView-setFrameSize(320,480); ,这里设置成你要的分辨率,用于开发。 Cocos2d-

思路

1)首先是横屏改为竖屏,因为android项目的screenOrientation默认为横屏;

2)设置自适应屏。

【二】:横竖换屏

1Cocos2d-x2.x,打开main.cpp文件

找到eglView->setFrameSize(320,480);,这里设置成你要的分辨率,用于开发。


Cocos2d-x3.x,则打开AppDelegate.cpp文件,在applicationDidFinishLaunching()里设置分辨率:glView->setFrameSizewidth,height;

2、生成android项目后修改AndroidManifest.xml文件

android:screenOrientation="landscape"横屏显示(默认)

android:screenOrientation="portrait"竖屏显示

 

【三】:自适应屏幕

这里算是个难点,应为android的开源,机型千奇百怪,我们没有办法去适应所有的屏幕,选择的方案也很多。

1、针对每个分辨率做一套方案(工程量太大);

2.cocos2dx2.0.4以后提供的缩放方案(相对1更适合);

使用方法:打开AppDelegate.cpp文件,找到:pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());在下面添加:

CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480,800, kResolutionNoBorder);

setDesignResolutionSize(设计宽,设计高,缩放方式);

该函数会自动按设计宽高和缩放方式适应手机屏幕。

缩放方式:

kResolutionExactFit       //自动缩放宽高全部显示(会变形)

kResolutionNoBorder    //不留黑边全屏展示(不变形,但是长的那边会被裁减)

kResolutionShowAll       //全部展示不裁剪(可能会留黑边)

【三】:适应相对坐标

我们坐标需要按照屏幕的实际大小来,所以也要使用相对坐标。

CCDirector::sharedDirector()->getVisibleSize();  //可视区域大小(用户手机分辨率)

CCDirector::sharedDirector()->getVisibleOrigin();//可视区域左下角坐标

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn