直接在代码,这是一个很好的包layer,可以直接调用 //原来白白
bool TestLayer::init() { CCSize size = CCDirector::sharedDirector()->getVisibleSize(); //创建要显示的文字 text = CCLabelTTF::create("text baibai fdffdd zimu haha jahjahjkd jhahaj ", "", 30); text->setPosition(ccp(100, -120)); //绘制裁剪区域 CCDrawNode* shap = CCDrawNode::create(); CCPoint point[4] = {ccp(0,0), ccp(200, 0), ccp(200, 200), ccp(0, 200)}; shap->drawPolygon(point, 4, ccc4f(355, 255, 255, 255), 2, ccc4f(255, 255, 255, 255)); CCClippingNode* cliper = CCClippingNode::create(); cliper->setStencil(shap); cliper->setAnchorPoint(ccp(.5, .5)); cliper->setPosition(ccp(100, 20)); addChild(cliper); //把要滚动的文字增加到裁剪区域 cliper->addChild(text); //文字滚动。超出范围后从新開始 schedule(schedule_selector(CTestLayer::rollText)); return true; } void TestLayer::rollText(float) { text->getPositionY()>300 ? text->setPositionY(-150) : text->setPositionY(text->getPositionY()+2); }
版权声明:本文博客原创文章,博客,未经同意,不得转载。