公告栏用的是CClayer(层)或者node节点,锚点位置是(0,0),
文字信息使用CCLabelTTF保存,锚点位置是(0,0),使用的时候将它加入到node里面就好了
文字移动的思路是:
每次都update公告的CCLabelTTF的坐标,为了让它
从右往左进行移动,右边栏出来,左边栏消失,需要设置一下CCLabelTTF的可
显示区域,CCLabelTTF::setTextureRect函数正是设置Label的可显示区域,因此左右边界需要特殊处理,解决方法:
HelloWorldScene.h
- #ifndef__HELLOWORLD_SCENE_H__
- #define__HELLOWORLD_SCENE_H__
- #include"cocos2d.h"
- #include<renren-ext.h>
- USING_NS_CC;
- classHelloWorld:publiccocos2d::CCLayer
- {
- public:
- //Here'sadifference.Method'init'incocos2d-xreturnsbool,insteadofreturning'id'incocos2d-iphone
- virtualboolinit();
- //there'sno'id'incpp,sowerecommendreturningtheclassinstancepointer
- staticcocos2d::CCScene*scene();
- //aselectorcallback
- voidmenuCloseCallback(CCObject*pSender);
- CREATE_FUNC(HelloWorld);
- //implementthe"staticnode()"methodmanually
- virtualvoidupdate(floatdelta);
- CCLabelTTF*adLabel;
- CCLayerColor*adCClayer;
- CCRectm_informRect;
- floatm_informScrollX;
- };
- #endif//__HELLOWORLD_SCENE_H__
- boolHelloWorld::init()
- {
- //////////////////////////////
- //1.superinitfirst
- if(!CCLayer::init())
- returnfalse;
- }
- CCSizevisibleSize=CCDirector::sharedDirector()->getVisibleSize();
- CCPointorigin=CCDirector::sharedDirector()->getVisibleOrigin();
- adCClayer=CCLayerColor::create(ccc4(255,100),300,30);
- adCClayer->setPosition(ccp(visibleSize.width/10,visibleSize.height/2+origin.y));
- adCClayer->setAnchorPoint(ccp(0,0));
- this->addChild(adCClayer);
- CCSizesize=adCClayer->getContentSize();
- adLabel=CCLabelTTF::create("helloworld","Arial",24);
- adLabel->setAnchorPoint(ccp(0,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> adLabel->setPosition(CCSize(size.width,0));
- m_informScrollX=size.width;
- m_informRect=adLabel->getTextureRect();
- this->scheduleUpdate();
- adCClayer->addChild(adLabel);
- true;
- }