Example #1
0
// When activated, scale the parent CCNode by the value of the activatedScale property.
// The current scale value of the parent is cached again, in case that scale had been
// changed since this adornment was added to the parent. We do not simply use a deactivation
// scale of 1 / activationScale in case the activation scaling is interrupted by the
// deactivation, and has not fully scaled up at the time the deactivation starts.
// The action is tagged so that it can be easily found if it needs to be cancelled.
void CCNodeAdornmentScaler::activate()
{
	CCNode* p = getParent();
	if ( p == NULL )
		return;

	CCAction* currAction = p->getActionByTag( kScaleActionTag );
	if ( currAction ) 
	{
		// if we already have an active action, cancel it
		p->stopAction( currAction );
	} 
	else
	{
		// only cache scale if a scaling action is not active
		// because otherwise scale will be evolvin and we'll cache something halfway
		setOriginalScaleFromParent();
	}
	// use scaleTo instead of scaleBy so that final size is deterministic in the case
	// where we have interrupted an active scaling action above
	float finalScaleX = _originalScale.width * _activatedScale.width;
	float finalScaleY = _originalScale.height * _activatedScale.height;
	CCAction* scaleAction = CCActionScaleTo::create( getActionDuration(), finalScaleX, finalScaleY );
	scaleAction->setTag( kScaleActionTag );
	p->runAction( scaleAction );
}
Example #2
0
void CSmeltArmor::showMoveAction( const char* name )
{
	CCNode* pNode = ((CCNode*)m_ui->findWidgetById(name));
	if(pNode->getActionByTag(999) == nullptr)
	{
		CCRepeatForever* pAction = CCRepeatForever::create(CCSequence::createWithTwoActions(CCMoveBy::create(0.7f, ccp(0, 15)), CCMoveBy::create(0.7f, ccp(0, -15))));
		pAction->setTag(999);
		pNode->runAction(pAction);
	}
}
Example #3
0
bool MainLayer::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{ /*-- 跳动作 --*/
	//CCDirector::sharedDirector()->replaceScene(FinishLayer::scene());
	CCSize vsize = CCDirector::sharedDirector()->getVisibleSize();
	CCPoint location = pTouch->getLocation();
	CCNode *node = 0;
	if (location.x < vsize.width / 2)
	{
		if (!leftJumping)
		{
			node = this->getChildByTag(TAG_LEFT);
			leftJumping = true;
		}
	}
	else
	{
		if (!rightJumping)
		{
			node = this->getChildByTag(TAG_RIGHT);
			rightJumping = true;
		}
	}
	if (node)
	{
		CCActionInterval *jump = CCJumpBy::create(speed / ratio, ccp(0, 0),
				node->getContentSize().height, 1);
		node->runAction(jump);
		CCActionInterval *moving = (CCActionInterval*) node->getActionByTag(
		TAG_ACTION_MOVE);
		if (moving)
		{
			node->runAction(CCSpeed::create(moving, 1.2f));
		}
		playJumpAnimation(node);
	}
	return true;
}