使用cocos studio界面自适应遇到问题及解决方法
2017-09-10 01:04
363 查看
如上图用Cocos Studio 3.10 创建的界面,其中两个Hello word 文本框都绑定在 一个 Node节点上,该Node节点限定在左上都20个像素位置。
模拟运行 iphone4 及 iphone5 确实达到了我的效果。
发布资源到工程中运行后发现在 iphone4 分辨率情况下 Hello Word 消失了。
经过一番盘查发现在界面加载的时候存在一定问题。
1.通过继承的如下方法来解析获得节点
virtual cocos2d::Node* createNodeWithFlatBuffers(const
flatbuffers::Table* nodeOptions)
2.解析过程会借用
LayoutComponent 这个类进行自适应设置
void
LayoutComponent::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();
}
}
}
3.但是在运行到获得父节点返回为空,原因是先解析后 addChild。
那么只要在 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);
return
nullptr;
}
Component* Node::getComponent(const
std::string& name)
{
if (_componentContainer)
return
_componentContainer->get(name);
return
nullptr;
}
此可见其数据还储存在 _componentContainer
最终如下修改
使用过程中场景文件的根节点都必须设为 sceneroot,然后对其大小进行根据winSize大小一次设定。
相关文章推荐
- Android Studio-—使用OpenCV的配置方法和demo以及开发过程中遇到的问题解决
- 虚拟IP实验,遇到场景启用使用虚拟IP就报错,不启用可以正常运行的问题,解决方法
- Java使用Oracle遇到的最大游标超出问题及其解决方法
- 使用pbrt 1.03遇到的问题和解决方法
- Python2.5使用新浪微博Python SDK遇到的问题与解决方法
- 使用Adobe PDF Reader组件遇到问题之解决方法
- Infragistics的NetAdvantage控件使用中遇到的问题及解决方法
- 使用printf修改变量的值 —— VS2008中使用%n输出遇到的问题及解决方法
- Eclipse使用遇到的问题解决方法收集
- LoadRunner在使用时遇到的问题及解决方法
- [Nebula2]使用3dmax7,nmaxtoolbox导出模型到nebula2遇到的问题及解决方法
- [原创]DateTime在使用 format Custom Date and Time Format Strings时遇到的问题和解决方法
- 使用session时候,遇到的一个问题(请求解决方法)
- Microsoft Visual Studio 遇到了问题,需要关闭的一种可能的解决方法(转载)
- 在xp和Win7上使用Tomcat 6.0经常遇到的几个问题及其解决方法
- 在.NET中发送邮件,使用回执功能中遇到问题的解决方法[在NOTES服务器上,C#,.NET2.0环境]
- VC++中使用ADO访问Oracle遇到的问题及解决方法(待续)
- 使用VIM开发软件项目 - (16) vim编译中遇到的问题及解决方法
- 使用GridView时遇到的一些小问题及解决方法
- J2ME使用WTK模拟器开发时候遇到“OK to use Airtime” 问题的解决方法