使用cocos studio界面自适应遇到问题及解决方法
来源:互联网 发布:龙泉驿广电网络全称 编辑:程序博客网 时间:2024/06/07 04:43
如上图用Cocos Studio 3.10 创建的界面,其中两个Hello word 文本框都绑定在 一个 Node节点上,该Node节点限定在左上都20个像素位置。
模拟运行 iphone4 及 iphone5 确实达到了我的效果。
发布资源到工程中运行后发现在 iphone4 分辨率情况下 Hello Word 消失了。
经过一番盘查发现在界面加载的时候存在一定问题。
1.通过继承的如下方法来解析获得节点
virtual cocos2d::Node* createNodeWithFlatBuffers(constflatbuffers::Table* nodeOptions)
voidLayoutComponent::setPositionPercentX(float percentMargin)
{
_positionPercentX = percentMargin;
if (_usingPositionPercentX ||_horizontalEdge == HorizontalEdge::Center)
{
Node* parent =this->getOwnerParent();
if (parent !=nullptr)
{
_owner->setPositionX(parent->getContentSize().width * _positionPercentX);
this->refreshHorizontalMargin();
}
}
}
那么只要在 node->addChild(child);
在进行一次设置即可。
加载过程会调用如下代码
LayoutComponent*LayoutComponent::bindLayoutComponent(Node* node)
{
LayoutComponent * layout = (LayoutComponent*)node->getComponent(__LAYOUT_COMPONENT_NAME);
if (layout !=nullptr)
return layout;
layout = new (std::nothrow)LayoutComponent();
if (layout && layout->init())
{
layout->autorelease();
node->addComponent(layout);
return layout;
}
CC_SAFE_DELETE(layout);
returnnullptr;
}
Component* Node::getComponent(conststd::string& name)
{
if (_componentContainer)
return_componentContainer->get(name);
returnnullptr;
}
此可见其数据还储存在 _componentContainer
最终如下修改
使用过程中场景文件的根节点都必须设为 sceneroot,然后对其大小进行根据winSize大小一次设定。
- 使用cocos studio界面自适应遇到问题及解决方法
- 使用Android studio 遇到的问题及解决方法
- 使用Android Studio时遇到的两个问题及解决方法
- Cocos Studio使用问题
- Laravel 使用遇到的问题及解决方法
- Laravel 使用遇到的问题及解决方法
- ubuntu使用中遇到问题及解决方法
- cocos studio: 界面模块化
- Android Studio安装遇到的问题及解决方法汇总
- 安装Android Studio遇到的问题及解决方法
- Android Studio中配置AndroidAnnotations,遇到的问题及解决方法
- Android Studio中配置AndroidAnnotations,遇到的问题及解决方法
- Eclipse工程导入Android Studio遇到的问题及解决方法
- 使用android studio中遇到的常见问题及解决方法
- 遇到问题及解决方法
- Cocos Studio及ListView使用简介
- Android Studio 使用中遇到的一些问题以及解决方法
- Cocos2d-JS中使用Cocos Studio资源03:设置界面
- 【安全牛学习笔记】DNS信息收集-DIG
- Mysql中的count()与sum()区别
- vue router-view详细讲解一
- arm-poky-linux-gnueabi- (5.3.0) 工具链编译live555-20170718
- Js使用arguments动态获取传参个数
- 使用cocos studio界面自适应遇到问题及解决方法
- aar 文件配置
- LeetCode 312: Brust Balloon 解题与思考
- 欢迎使用CSDN-markdown编辑器
- 机器学习中的范数规则化之----L0、L1与L2范数
- lamda表达式
- Spring事务管理-编程式事务、声明式事务
- 简单的C语言链表(含输入、输出功能)
- 系统编程之文件的操作day1