I’m trying to use CCClippingNode to make a nice scrollable text that is inside a message box. It’s working fine but there’s a white rectangle that appears for some seconds and disappears suddenly. It only started to appear after my implementation of ClippingNode, but looking at the sample in TestCPP, I can’t find what’s wrong in my implementation…
Important: I’ve noticed this “error” occurring only when I’m using a fade transition to/from other scene. If i just replace scene, the white rectangle doesn’t show up.
Here’s the code and SS:
InfoLayer.cpp - a message box with no buttons - In main code I call onLoad* after usingInfoLayer::create();*
void InfoLayer::onLoad() {
infoBGSprite = CCSprite::createWithSpriteFrameName(s_BGInfo);
infoBGSprite->setScale(Constants::scale);
infoBGSprite->setPosition(CCPointZero);
width = infoBGSprite->getTextureRect().size.width * Constants::scale;
clippingNode = CCClippingNode::create(infoBGSprite);
textLabel = CCLabelTTF::create("Info Text", s_FontPath, 24 * Constants::scale);
textLabel->setHorizontalAlignment(kCCTextAlignmentCenter);
textLabel->setVerticalAlignment(kCCVerticalTextAlignmentCenter);
textLabel->setColor(ccc3(20, 20, 20));
textLabel->setAnchorPoint(ccp(0.5f, 1));
textLabel->setDimensions(CCSizeMake(infoBGSprite->getTextureRect().size.width * Constants::scale * 0.9f, 0));
textLabel->setPosition(CCPointZero);
addChild(infoBGSprite);
clippingNode->addChild(textLabel);
addChild(clippingNode);
clippingNode->setPosition(CCPointZero);
}
void InfoLayer::onEnter() {
CCLayer::onEnter();
setTouchEnabled(true);
}
void InfoLayer::ccTouchesBegan(CCSet* pTouches, CCEvent* pEvent) {
CCTouch *touch = (CCTouch*)pTouches->anyObject();
CCPoint point = clippingNode->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(touch->getLocationInView()));
lastPoint = point;
isScrolling = true;
}
void InfoLayer::ccTouchesMoved(CCSet* pTouches, CCEvent* pEvent) {
CCTouch *touch = (CCTouch*)pTouches->anyObject();
CCPoint point = clippingNode->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(touch->getLocationInView()));
CCPoint diff = ccpSub(point, lastPoint);
//float diffY = point.y - lastPoint.y;
textLabel->setPositionY(diff.y + textLabel->getPositionY());
lastPoint = point;
isScrolling = true;
}
void InfoLayer::ccTouchesEnded(CCSet* pTouches, CCEvent* pEvent) {
isScrolling = false;
}
void InfoLayer::update(float dt) {
if(!isScrolling) {
textLabel->setPositionY(textLabel->getPositionY() + 1 * Constants::scale);
if(textLabel->getPositionY() > infoBGSprite->getContentSize().height * Constants::scale + textLabel->getContentSize().height) {
textLabel->setPositionY(-infoBGSprite->getContentSize().height * Constants::scale / 2);
}
}
}
void InfoLayer::setText(const char* text) {
textLabel->setString(text);
}
float InfoLayer::getWidth() {
return width;
}
device-2013-02-11-021917.png (299.7 KB)