遮罩效果的实现问题

问题,在visit 方法中 获取 位置进行 遮罩效果,但是发现想x y 位置不对,使用后不能显示,使用行2 才能显示成功? 为啥呢,,感谢各位帮忙

void NumberScrollLabel::visit()
{

//启动遮罩效果
glEnable(GL_SCISSOR_TEST);

CCPoint pos = CCPointZero;

 pos = visibleNode->getParent()->convertToWorldSpace(pos); //获取屏幕绝对位置
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>pos.x %f \n", pos.x);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>pos.y %f \n", pos.y);

行1 CCRect rect = CCRectMake(pos.x, pos.y, 40, 40);
行2 //CCRect rect = CCRectMake(pos.x+60, pos.y+245, 40, 40);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>rect.origin.x %f \n", rect.origin.x);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>rect.origin.y %f \n", rect.origin.y);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>rect.size.width %f \n", rect.size.width);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>rect.size.height %f \n", rect.size.height);
//设置遮罩效果

glScissor(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
}
CCNode::visit();

//关闭遮罩效果
glDisable(GL_SCISSOR_TEST);

}

Cocos2d 版本为 2.2.1

.。。。。。。。求解答

pos = visibleNode->getParent()->convertToWorldSpace(pos);
改为pos = visibleNode->getParent()->convertToWorldSpace(visibleNode->getPosition());

还是不对呀。。。

全部代码

#include “NumberScrollLabel.h”
USING_NS_CC;

NumberScrollLabel::NumberScrollLabel(void)
{
}

NumberScrollLabel::~NumberScrollLabel(void)
{
}

bool NumberScrollLabel::init()
{
labels=CCArray::create();
nowIndex = 0;
int numHeight = 20;

labels = CCArray::createWithCapacity(10);
labels->retain();

visibleNode = CCNode::create();
this->addChild(visibleNode);

for(int i = 0; i < 10; i++) {
    char str;
    str = '0' + i;
    str = '\0';

    CCLabelTTF* single = CCLabelTTF::create(str, "arial", numHeight);//Arial
    single->setTag(i);
    single->setAnchorPoint(ccp(0, 0));
    single->setPosition(ccp(0, numHeight * i));
    visibleNode->addChild(single);
    labels->addObject(single);
    labelsY* = single->getPositionY();
    //labels->retain();
}

CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>NumberScrollLabel::init %d \n", labels->count());
return true;

}

void NumberScrollLabel::setNumber(int i)
{
if(i<0 || i>9){
return;
}
//CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>NumberScrollLabel::setNumber %d \n", labels->count());
nowIndex = i;
//CCLabelTTF* tmp = (CCLabelTTF*)labels->objectAtIndex(i);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>NumberScrollLabel::labelsY* %d ,i: %d \n", labelsY*,i);

this->stopAllActions();
CCPoint moveToPosition = ccp(visibleNode->getPosition().x,-labelsY*);
CCMoveTo* moveAction = CCMoveTo::create(0.5, moveToPosition);
visibleNode->runAction(moveAction);

}

void NumberScrollLabel::updateTimer()
{
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>NumberScrollLabel::setNumber %d \n", labels->count());
if(nowIndex >=9){
nowIndex = 0;
}else{
nowIndex = nowIndex + 1;
}
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>NumberScrollLabel::setNumber nowIndex %d \n", nowIndex);
setNumber(nowIndex);
}

int NumberScrollLabel::getNumber()
{
return nowIndex;
}

void NumberScrollLabel::visit()
{
bool b = true;
if(b){
//启动遮罩效果
glEnable(GL_SCISSOR_TEST);

CCPoint pos = CCPointZero;
/*
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>visibleNode->getPositionX() %f \n", visibleNode->getPositionX());
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>visibleNode->getPositionY() %f \n", visibleNode->getPositionY());

pos = CCDirector::sharedDirector()->convertToGL(pos);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>convertToGL.x %f \n", pos.x);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>convertToGL.y %f \n", pos.y);
CCPoint posd = visibleNode->convertToNodeSpace(CCPointZero);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>posd.x %f \n", posd.x);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>posd.y %f \n", posd.y);
posd = visibleNode->getParent() ->convertToNodeSpaceAR(CCPointZero);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>> ->getParent()>posd.x %f \n", posd.x);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>> ->getParent()>posd.y %f \n", posd.y);
posd = visibleNode->getParent()->getParent()->convertToNodeSpaceAR(CCPointZero);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>->getParent()->getParent()>posd.x %f \n", posd.x);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>->getParent()->getParent()>posd.y %f \n", posd.y);
CCPoint posdw = visibleNode->getParent()->getParent()->convertToWorldSpace(CCPointZero);

CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>posdw.x %f \n", posdw.x);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>posdw.y %f \n", posdw.y);
*/
// pos = visibleNode->getParent()->convertToWorldSpace(pos); //获取屏幕绝对位置
pos = visibleNode->getParent()->convertToWorldSpace(CCPointZero);
 
CCPoint location = CCDirector::sharedDirector()->convertToGL(pos);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>location.x %f \n", location.x);
 CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>location.y %f \n", location.y);


 CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>pos.x %f \n", pos.x);
 CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>pos.y %f \n", pos.y);
CCDirector* pDirector = CCDirector::sharedDirector();
float f = pDirector->getContentScaleFactor();
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>pDirector->getContentScaleFactor() %f \n", f);
///CCRect rect = CCRectMake(pos.x, pos.y, 40, 40);
CCRect rect = CCRectMake(pos.x-15, pos.y+155, 20,30);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>rect.origin.x %f \n", rect.origin.x);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>rect.origin.y %f \n", rect.origin.y);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>rect.size.width %f \n", rect.size.width);
CCLOG (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>rect.size.height %f \n", rect.size.height);
//设置遮罩效果

glScissor(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
}
CCNode::visit();

//关闭遮罩效果
glDisable(GL_SCISSOR_TEST);

}


我记得用ccrendertexture的visit的话,虽然是ccnode,需要把ccnode的y方向翻转,定位也是左上为(0,0)
不知道这里是不是这个原因

既是opengl的函数,自然应该用opengl的坐标系。楼上说的有理。