Exemplo n.º 1
0
NoPL_FunctionValue Node::evaluateFunction(const char* functionName, const NoPL_FunctionValue* argv, unsigned int argc)
{
	NoPL_FunctionValue returnVal;
	returnVal.type = NoPL_DataType_Uninitialized;
	
	if(node)
	{
		if(argc == 0)
		{
			if(!strcmp(functionName, "worldPositionX"))
			{
				returnVal.numberValue = node->convertToWorldSpaceAR(cocos2d::CCPointZero).x;
				returnVal.type = NoPL_DataType_Number;
			}
			else if(!strcmp(functionName, "worldPositionY"))
			{
				returnVal.numberValue = node->convertToWorldSpaceAR(cocos2d::CCPointZero).y;
				returnVal.type = NoPL_DataType_Number;
			}
		}
		else if(!strcmp(functionName, "hitTest"))
		{
			if(argc == 2 &&
			   argv[0].type == NoPL_DataType_Number &&
			   argv[1].type == NoPL_DataType_Number)
			{
				returnVal.booleanValue = (node->hitTest(cocos2d::CCPoint(argv[0].numberValue, argv[1].numberValue)));
				returnVal.type = NoPL_DataType_Boolean;
			}
			else if(argc == 1 && argv[0].type == NoPL_DataType_Pointer)
			{
				cocos2d::CCObject* arg = (cocos2d::CCObject*)argv[0].pointerValue;
				Node* otherNode = dynamic_cast<Node*>(arg);
				if(otherNode && otherNode->getCCNode())
				{
					//get the transforms for each node
					cocos2d::CCAffineTransform thisTransform = node->nodeToWorldTransform();
					cocos2d::CCAffineTransform nodeTransform = otherNode->getCCNode()->nodeToWorldTransform();
					
					//create a rect for each node in the same coord system
					cocos2d::CCRect thisRect;
					thisRect.origin = CCPointApplyAffineTransform(cocos2d::CCPoint(0,0), thisTransform);
					thisRect.size = CCSizeApplyAffineTransform(node->getContentSize(), thisTransform);
					cocos2d::CCRect nodeRect;
					nodeRect.origin = CCPointApplyAffineTransform(cocos2d::CCPoint(0,0), nodeTransform);
					nodeRect.size = CCSizeApplyAffineTransform(otherNode->getCCNode()->getContentSize(), nodeTransform);
					
					//return the result of the hit test
					returnVal.booleanValue = thisRect.intersectsRect(nodeRect);
					returnVal.type = NoPL_DataType_Boolean;
				}
			}
		}
	}
	
	if(returnVal.type == NoPL_DataType_Uninitialized)
		return Node_Base::evaluateFunction(functionName, argv, argc);
	return returnVal;
}
Exemplo n.º 2
0
void CAWebView::update(float dt)
{
    do
    {
        CC_BREAK_IF(!CAApplication::getApplication()->isDrawing());
        CCPoint point = this->convertToWorldSpace(m_obPoint);
        CCSize contentSize = CCSizeApplyAffineTransform(m_obContentSize, worldToNodeTransform());
        CC_BREAK_IF(m_obLastPoint.equals(point) && m_obLastContentSize.equals(contentSize));
        m_obLastPoint = point;
        m_obLastContentSize = contentSize;
        
		CCSize size = getBounds().size;
		m_pLoadingView->setFrame(CCRect(size.width*0.5f, size.height*0.3f, size.width*0.2f, size.height*0.2f));
        _impl->update(dt);
    }
    while (0);
}
Exemplo n.º 3
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);
}