全部代码
#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);
}