cocos2dx 3.x designResolutionSize须主动设置

cocos2dx 3.x最初设置screenSize和designResolutionSize的地方如下:

bool AppDelegate::applicationDidFinishLaunching() {

// initialize director

auto director = Director::getInstance();

auto glview = director->getOpenGLView();

if(!glview) {

glview = GLViewImpl::create("title");

director->setOpenGLView(glview);

}

  ...

}

在iOS target下(在mac target下代码不一样),GLViewImpl::create(...)的实现代码如下:

GLViewImpl* GLViewImpl::create(const std::string& viewName)

{

auto ret = new (std::nothrow) GLViewImpl;

if(ret && ret->initWithFullScreen(viewName)) {

ret->autorelease();

return ret;

}

return nullptr;

}

bool GLViewImpl::initWithFullScreen(const std::string& viewName)

{

CGRect rect = [[UIScreen mainScreen] bounds];

Rect r;

r.origin.x = rect.origin.x;

r.origin.y = rect.origin.y;

r.size.width = rect.size.width;

r.size.height = rect.size.height;

return initWithRect(viewName, r, 1);

}

bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float frameZoomFactor)

{

CGRect r = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);

convertAttrs();

CCEAGLView *eaglview = [CCEAGLView viewWithFrame: r

pixelFormat: (NSString*)_pixelFormat

depthFormat: _depthFormat

preserveBackbuffer: NO

sharegroup: nil

multiSampling: NO

numberOfSamples: 0];

[eaglview setMultipleTouchEnabled:YES];

_screenSize.width = _designResolutionSize.width = [eaglview getWidth];

_screenSize.height = _designResolutionSize.height = [eaglview getHeight];

//    _scaleX = _scaleY = [eaglview contentScaleFactor];

_eaglview = eaglview;

return true;

}

可见,默认cocos2dx 3.x会将designresolutionsize设成与screensize相等,于是显示效果如果在iphone上正常的话在ipad上肯定就不对了,所以我们必须主动设designresolutionsize。

例如,可以在创建完glview后设置designResolutionSize:

bool AppDelegate::applicationDidFinishLaunching() {

// initialize director

auto director = Director::getInstance();

auto glview = director->getOpenGLView();

if(!glview) {

glview = GLViewImpl::create("title");

director->setOpenGLView(glview);

}

//added by[yang chao]

//by default glview is created "fullscreen", namely screenSize = designResolutionSize.width = eaglview size

//but this is not what we want, we want use our own designResolutionSize, so we should set designResolution ourselves

{

director->getOpenGLView()->setDesignResolutionSize(1136,640,ResolutionPolicy::NO_BORDER);

}

  

 ...

}

时间: 2024-09-21 00:58:58

cocos2dx 3.x designResolutionSize须主动设置的相关文章

nginx中lua主动设置Content-Length

最近发现lua调用ngx.say和ngx.print 默认返回的HTTP头是trunk模式的,通常情况下是很好的,没有什么问题:但是要提供给其他人回源的时候就有问题了,特别是我要给slice模块回源,所以需要主动设置Content-Length,按照下面这是设置就OK了 ngx.header["Content-Length"]="4"; ngx.print("success")l ngx.exit(ngx.OK); 原文地址:https://ww

cocos2dx中setContentSize与setDimensions在设置label显示区域上的区别

作者:Coder-Chen链接:http://www.zhihu.com/question/38808257/answer/78333888来源:知乎著作权归作者所有,转载请联系作者获得授权. 其他他们直接的差别不大,都是节点未转化前大小!Dimensions翻译为:规模,大小:我们先看一下他们的源码: /** Sets the untransformed size of the Label in a more efficient way.(其实就是一种更加高效的设置Size的方式) */voi

cocos2d-x 3.0 版本 骨骼动画设置shader

因为骨骼动画是由多个sprite组成, 所以需要遍历每个sprite 才能修改整体, 开头这样设置,在游戏中发现走路状态没问题,攻击状态就有部分sprite没效果 for (auto & object : armObj->getBoneDic()) { if (cocostudio::Bone *bone = dynamic_cast<cocostudio::Bone *>(object.second)) { Node *node = bone->getDisplayRen

quick cocos2dx lua 网络图片 下载 自己主动更新

转载请注明,原文地址:http://blog.csdn.net/dd135373/article/details/46468505 quick coocs2d-x 网络图片下载,自己主动更新纹理,保存url的md5作为标记.假设本地存在,直接读取本地. NetSprite.new(url):addTo(self):align(display.CENTER,0,0) 版权声明:本文博主原创文章,博客,未经同意不得转载.

关于Cocos2d-x中多边形物理刚体的设置

1.如果想要设置某个物体有多边形的刚体,这样可以更精确地进行碰撞检测,可以用以下的方法 auto hero = PlaneHero::create(); addChild(hero, 0, HERO_TAG); hero->setPosition(Vec2(winSize.width / 2, hero->getContentSize().height / 2 + 10)); //auto herobody = PhysicsBody::createBox(hero->getConten

Cocos2d-x开发之第二篇《设置模拟器大小及实际分辨率》

接上一篇<创建工程> 1.在D:\cocos2d-x-2.2.5\projects\MyGame\proj.win32中有main.cpp文件,内容如下: 其中的eglView->setFrameSize(480, 320)是设置模拟器大小的(相当于是手机的实际尺寸),大家可以根据实际情况进行设置. 2.在D:\cocos2d-x-2.2.5\projects\MyGame\Classes中的AppDelegate.cpp是整个游戏的代理文件.由于考虑到Android手机各种屏幕分辨率问

(转)cocos2d-x 每帧动画的播放设置一个监听函数的做法

1 local cache = cc.AnimationCache:getInstance() 2 cache:addAnimations("animations-2.plist") 3 local animation = cache:getAnimation("dance_1") 4 animation:setDelayPerUnit(0.25) 5 animation:setRestoreOriginalFrame(true) 6 local aniamte =

cocos2d-x 移植android竖,横屏设置

AndroidManifest.xml于android:screenOrientation现场控制屏幕方向,默认为横屏 android:screenOrientation="landscape" //横屏 android:screenOrientation="portrait"//肯尼迪屏幕 版权声明:本文博主原创文章,博客,未经同意不得转载.

cocos2d-x 3.0rc开发指南:Windows下Android环境搭建

安装工具 1. 配置JDK JDK下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html 本人的系统是Win7 64位版,但安装的是JDK7.Windows X86版. 如果安装文件夹在:C:\Program Files (x86)\Java\jdk1.7.0_21:当然也能够是其它地方 环境变量设置: JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0_21 CLA