使用裁剪框来做滚动字幕,代码如下
#include "cocos2d.h"
USING_NS_CC;
// 裁剪框
class TailorView : public CCLayer
{
public:
virtual void visit(void);
static TailorView* create(const CCSize &size);
private:
};
#include "TailorView.h"
//裁剪框
void TailorView::visit( void )
{
glEnable(GL_SCISSOR_TEST); // 开启显示指定区域
float x = this->getPositionX();
float y = this->getPositionY();
float n_width = this->getContentSize().width;
float n_height = this->getContentSize().height;
CCPoint p = this->convertToWorldSpace(ccp(0,0));
CCPoint pw = this->convertToWorldSpace(ccp(n_width,n_height));
CCDirector::sharedDirector()->getOpenGLView()->setScissorInPoints(p.x, p.y,pw.x-p.x, pw.y-p.y);
CCLayer::visit();
glDisable(GL_SCISSOR_TEST);
}
TailorView* TailorView::create( const CCSize &size)
{
TailorView* pLayer = new TailorView();
pLayer->setAnchorPoint( ccp(0,0));
pLayer->setContentSize(size);
pLayer->setPosition( 0,0);
pLayer->autorelease();
return pLayer;
}
直接创建CCLabelTTF添加到 TailorView 就好了!使用update来更新CCLabelTTF的位置