コード例 #1
0
ファイル: ClippingNodeTest.cpp プロジェクト: 1901/cocos2d-x
void ScrollViewDemo::setup()
{
    CCClippingNode *clipper = CCClippingNode::create();
    clipper->setTag( kTagClipperNode );
    clipper->setContentSize(  CCSizeMake(200, 200) );
    clipper->setAnchorPoint(  ccp(0.5, 0.5) );
    clipper->setPosition( ccp(this->getContentSize().width / 2, this->getContentSize().height / 2) );
    clipper->runAction(CCRepeatForever::create(CCRotateBy::create(1, 45)));
    this->addChild(clipper);

    CCDrawNode *stencil = CCDrawNode::create();
    CCPoint rectangle[4];
    rectangle[0] = ccp(0, 0);
    rectangle[1] = ccp(clipper->getContentSize().width, 0);
    rectangle[2] = ccp(clipper->getContentSize().width, clipper->getContentSize().height);
    rectangle[3] = ccp(0, clipper->getContentSize().height);
    
    ccColor4F white = {1, 1, 1, 1};
    stencil->drawPolygon(rectangle, 4, white, 1, white);
    clipper->setStencil(stencil);

    CCSprite *content = CCSprite::create(s_back2);
    content->setTag( kTagContentNode );
    content->setAnchorPoint(  ccp(0.5, 0.5) );
    content->setPosition( ccp(clipper->getContentSize().width / 2, clipper->getContentSize().height / 2) );
    clipper->addChild(content);
    
    m_bScrolling = false;

    this->setTouchEnabled(true);
}
コード例 #2
0
ファイル: ClippingNodeTest.cpp プロジェクト: 1901/cocos2d-x
void BasicTest::setup()
{
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCNode *stencil = this->stencil();
    stencil->setTag( kTagStencilNode );
    stencil->setPosition( ccp(50, 50) );
    
    CCClippingNode *clipper = this->clipper();
    clipper->setTag( kTagClipperNode );
    clipper->setAnchorPoint(ccp(0.5, 0.5));
    clipper->setPosition( ccp(s.width / 2 - 50, s.height / 2 - 50) );
    clipper->setStencil(stencil);
    this->addChild(clipper);
    
    CCNode *content = this->content();
    content->setPosition( ccp(50, 50) );
    clipper->addChild(content);
}