Exemplo n.º 1
0
void HoleDemo::setup()
{
    CCSprite *target = CCSprite::create(s_pPathBlock);
    target->setAnchorPoint(CCPointZero);
    target->setScale(3);
    
    m_pOuterClipper = CCClippingNode::create();
    m_pOuterClipper->retain();
    CCAffineTransform tranform = CCAffineTransformMakeIdentity();
    tranform = CCAffineTransformScale(tranform, target->getScale(), target->getScale());

    m_pOuterClipper->setContentSize( CCSizeApplyAffineTransform(target->getContentSize(), tranform));
    m_pOuterClipper->setAnchorPoint( ccp(0.5, 0.5) );
    m_pOuterClipper->setPosition( ccpMult(ccpFromSize(this->getContentSize()), 0.5f) );
    m_pOuterClipper->runAction(CCRepeatForever::create(CCRotateBy::create(1, 45)));
    
    m_pOuterClipper->setStencil( target );
    
    CCClippingNode *holesClipper = CCClippingNode::create();
    holesClipper->setInverted(true);
    holesClipper->setAlphaThreshold( 0.05f );
    
    holesClipper->addChild(target);
    
    m_pHoles = CCNode::create();
    m_pHoles->retain();
    
    holesClipper->addChild(m_pHoles);
    
    m_pHolesStencil = CCNode::create();
    m_pHolesStencil->retain();
    
    holesClipper->setStencil( m_pHolesStencil);
    
    m_pOuterClipper->addChild(holesClipper);
    
    this->addChild(m_pOuterClipper);
        
    this->setTouchEnabled(true);
}
Exemplo n.º 2
0
CCAffineTransform CCNode::nodeToParentTransform(void)
{
	if ( m_bIsTransformDirty ) {

		m_tTransform = CCAffineTransformIdentity;

		if( ! m_bIsRelativeAnchorPoint && ! CCPoint::CCPointEqualToPoint(m_tAnchorPointInPixels, CCPointZero) )
			m_tTransform = CCAffineTransformTranslate(m_tTransform, m_tAnchorPointInPixels.x, m_tAnchorPointInPixels.y);

		if( ! CCPoint::CCPointEqualToPoint(m_tPositionInPixels, CCPointZero) )
			m_tTransform = CCAffineTransformTranslate(m_tTransform, m_tPositionInPixels.x, m_tPositionInPixels.y);
		if( m_fRotation != 0 )
			m_tTransform = CCAffineTransformRotate(m_tTransform, -CC_DEGREES_TO_RADIANS(m_fRotation));
		if( ! (m_fScaleX == 1 && m_fScaleY == 1) ) 
			m_tTransform = CCAffineTransformScale(m_tTransform, m_fScaleX, m_fScaleY);

		if( ! CCPoint::CCPointEqualToPoint(m_tAnchorPointInPixels, CCPointZero) )
			m_tTransform = CCAffineTransformTranslate(m_tTransform, -m_tAnchorPointInPixels.x, -m_tAnchorPointInPixels.y);

		m_bIsTransformDirty = false;
	}

	return m_tTransform;
}