开启相对布局后,程序中直接写的控件加入根节点后,设置位置无效,默认位置一直在左上角,怎么破~~~~~

开启相对布局后,程序中直接写的控件加入根节点后,设置位置无效,默认位置一直在左上角,怎么破~~~~~

我现在把控件放在根节点上的图片(imageView上),默认的ccp(0,0)位置是图片中心(屏幕中心),然后可以设置了,不过感觉怪怪的。为什么不和openGL坐标重合。根节点修改为绝对布局就可以设置位置了

setPositionpercent()

没用啊:9:
代码
testButton = Button::create();
testButton->setTouchEnabled(true);
testButton->loadTextures(“loadingbar.png”, “loadingbar.png”, “”);
// testButton->setPositionType(POSITION_PERCENT);
//testButton->setPosition(Point(100, 0));
// testButton->setPositionPercent(ccp(0,0));
testButton->setPositionPercent(ccp(200,50));
// testButton->ignoreAnchorPointForPosition(false);
// testButton->ignoreContentAdaptWithSize(true);
// testButton->setAnchorPoint(ccp(0,0));
rootLayout->addChild(testButton,100);

这个是系数哦~~注意下参数

要设置相对位置才会有效,具体函数忘记了!你找下 dolayout()这个函数 应该就能知道

我的也是设置位置无效,搞了一晚上了,无解呀,到底要怎么搞