本文整理汇总了C++中CCAction类的典型用法代码示例。如果您正苦于以下问题:C++ CCAction类的具体用法?C++ CCAction怎么用?C++ CCAction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CCAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: callfunc_selector
void GameLayer::playerJump()
{
// check whether can jump
CCSprite *playerSprite = (CCSprite *)this->getChildByTag(PlayerTag);
if (playerSprite->getActionByTag(PlayerChangeRoadTag)) {
return;
}
if (playerSprite->getActionByTag(PlayerJumppingTag)) {
// already jump
return;
}
CCScaleTo *scaleTo = CCScaleTo::create(0.2, 1.2);
CCDelayTime *delay = CCDelayTime::create(0.6);
CCScaleTo *scaleBack = CCScaleTo::create(0.2, 1.0);
CCAction *action = CCSequence::create(scaleTo, delay, scaleBack, CCCallFunc::create(this, callfunc_selector(GameLayer::playerRun)), NULL);
action->setTag(PlayerJumppingTag);
if (isSliding) {
playerSprite->stopActionByTag(PlayerSlidingTag);
isSliding = false;
}
isJumpping = true;
playerSprite->runAction(action);
}
示例2: CCAssert
CCAction* CCActionManager::getActionByTag(unsigned int tag, CAObject *pTarget)
{
CCAssert((int)tag != kCCActionTagInvalid, "");
tHashElement *pElement = NULL;
HASH_FIND_INT(m_pTargets, &pTarget, pElement);
if (pElement)
{
if (pElement->actions != NULL)
{
unsigned int limit = pElement->actions->num;
for (unsigned int i = 0; i < limit; ++i)
{
CCAction *pAction = (CCAction*)pElement->actions->arr[i];
if (pAction->getTag() == (int)tag)
{
return pAction;
}
}
}
CCLOG("CrossApp : getActionByTag(tag = %d): Action not found", tag);
}
else
{
// CCLOG("CrossApp : getActionByTag: Target not found");
}
return NULL;
}
示例3:
//------------------------------------------------------------------
//
// Test5
//
//------------------------------------------------------------------
Test5::Test5()
{
CCSprite* sp1 = CCSprite::spriteWithFile(s_pPathSister1);
CCSprite* sp2 = CCSprite::spriteWithFile(s_pPathSister2);
sp1->setPosition(CCPointMake(100,160));
sp2->setPosition(CCPointMake(380,160));
CCRotateBy* rot = CCRotateBy::actionWithDuration(2, 360);
CCActionInterval* rot_back = rot->reverse();
CCAction* forever = CCRepeatForever::actionWithAction(
(CCActionInterval*)(CCSequence::actions(rot, rot_back, NULL))
);
CCAction* forever2 = (CCAction*)(forever->copy()->autorelease());
forever->setTag(101);
forever2->setTag(102);
addChild(sp1, 0, kTagSprite1);
addChild(sp2, 0, kTagSprite2);
sp1->runAction(forever);
sp2->runAction(forever2);
schedule( schedule_selector(Test5::addAndRemove), 2.0f);
}
示例4: ccp
void MainLayer::createNewRole()
{
CCSize vsize = CCDirector::sharedDirector()->getVisibleSize();
float width = vsize.width / 2;
float height = vsize.height / 2;
CCSprite *left = CCSprite::createWithSpriteFrameName("ultraman_big_1.png");
CCSprite *right = CCSprite::createWithSpriteFrameName("dragon_big_1.png");
if (CCRANDOM_0_1() < 0.5)
{
left->setScale(0.5f);
}
else
{
right->setScale(0.5f);
}
left->setPosition(ccp(-width, -height + 230));
left->setAnchorPoint(ccp(0, 0));
this->addChild(left, 3, TAG_LEFT);
right->setPosition(ccp(width, -height + 230));
right->setAnchorPoint(ccp(1, 0));
this->addChild(right, 3, TAG_RIGHT);
CCAction *leftMoving = CCMoveBy::create(speed, ccp(2 * width, 0));
CCAction *rightMoving = CCMoveBy::create(speed, ccp(-2 * width, 0));
leftMoving->setTag(TAG_ACTION_MOVE);
rightMoving->setTag(TAG_ACTION_MOVE);
left->runAction(leftMoving);
right->runAction(rightMoving);
disappearing = false;
/*-- 走路动画 --*/
playRunAnimation();
}
示例5: ccp
void SpriteEase::onEnter()
{
EaseSpriteDemo::onEnter();
CCActionInterval* move = CCMoveBy::create(3, ccp(VisibleRect::right().x-130,0));
CCActionInterval* move_back = move->reverse();
CCActionInterval* move_ease_in = CCEaseIn::create((CCActionInterval*)(move->copy()->autorelease()), 2.5f);
CCActionInterval* move_ease_in_back = move_ease_in->reverse();
CCActionInterval* move_ease_out = CCEaseOut::create((CCActionInterval*)(move->copy()->autorelease()), 2.5f);
CCActionInterval* move_ease_out_back = move_ease_out->reverse();
CCDelayTime *delay = CCDelayTime::create(0.25f);
CCSequence* seq1 = CCSequence::create(move, delay, move_back, CCCA(delay), NULL);
CCSequence* seq2 = CCSequence::create(move_ease_in, CCCA(delay), move_ease_in_back, CCCA(delay), NULL);
CCSequence* seq3 = CCSequence::create(move_ease_out, CCCA(delay), move_ease_out_back, CCCA(delay), NULL);
CCAction *a2 = m_grossini->runAction(CCRepeatForever::create(seq1));
a2->setTag(1);
CCAction *a1 = m_tamara->runAction(CCRepeatForever::create(seq2));
a1->setTag(1);
CCAction *a = m_kathia->runAction(CCRepeatForever::create(seq3));
a->setTag(1);
schedule(schedule_selector(SpriteEase::testStopAction), 6.25f);
}
示例6: unscheduleAll
void HFViewport::scrollToSmooth(const CCPoint& targetPoint, CCCallFunc* callbackFunc,float time)
{
unscheduleAll();
mIsProcessingScroll = true;
do
{
this->mTouchMode = TouchMode_Fling;
CCPoint curPos = this->m_TargetNode->getPosition();
CCPoint targetPos = targetPoint;
CCSize winsize = CCDirector::sharedDirector()->getWinSize();
if (targetPos.x >0.0f) {
targetPos.x = curPos.x;
}
if (targetPos.x <winsize.width-MAP_WIDTH*this->m_TargetNode->getScaleX()){
targetPos.x = winsize.width-MAP_WIDTH*this->m_TargetNode->getScaleX();
}
if (targetPos.y >0.0f) {
targetPos.y = curPos.y;
}
if (targetPos.y <winsize.height-MAP_HEIGHT*this->m_TargetNode->getScaleY()){
targetPos.y =winsize.height-MAP_HEIGHT*this->m_TargetNode->getScaleY();
}
CCMoveTo* move = CCMoveTo::create(time, targetPos);
CCAction* action = CCSequence::create(move,callbackFunc,NULL);
action->setTag(FLINGACTION_TAG);
this->m_TargetNode->runAction(action);
}
while(0);
mIsProcessingScroll = false;
}
示例7: assert
CCAction* CCActionManager::getActionByTag(int tag, NSObject *pTarget)
{
assert(tag != kCCActionTagInvalid);
tHashElement *pElement = NULL;
HASH_FIND_INT(m_pTargets, &pTarget, pElement);
if (pElement)
{
if (pElement->actions != NULL)
{
unsigned int limit = pElement->actions->num;
for (unsigned int i = 0; i < limit; ++i)
{
CCAction *pAction = (CCAction*)pElement->actions->arr[i];
if (pAction->getTag() == tag)
{
return pAction;
}
}
}
CCLOG("cocos2d : getActionByTag: Action not found");
}
else
{
CCLOG("cocos2d : getActionByTag: Target not found");
}
return NULL;
}
示例8: ccp
//------------------------------------------------------------------
//
// SpriteEase
//
//------------------------------------------------------------------
KDvoid SpriteEase::onEnter ( KDvoid )
{
TestEaseActions::onEnter ( );
const CCSize& s = this->getContentSize ( );
CCActionInterval* move = CCMoveBy::create(3, ccp(s.cx-130,0 ) );
CCActionInterval* move_back = move->reverse();
CCActionInterval* move_ease_in = CCEaseIn::create ( CCCA ( move ), 2.5f);
CCActionInterval* move_ease_in_back = move_ease_in->reverse();
CCActionInterval* move_ease_out = CCEaseOut::create ( CCCA ( move ), 2.5f);
CCActionInterval* move_ease_out_back = move_ease_out->reverse();
CCDelayTime *delay = CCDelayTime::create(0.25f);
CCSequence* seq1 = CCSequence::create(move, delay, move_back, CCCA(delay), KD_NULL);
CCSequence* seq2 = CCSequence::create(move_ease_in, CCCA(delay), move_ease_in_back, CCCA(delay), KD_NULL);
CCSequence* seq3 = CCSequence::create(move_ease_out, CCCA(delay), move_ease_out_back, CCCA(delay), KD_NULL);
CCAction *a2 = m_grossini->runAction(CCRepeatForever::create ( seq1 ) );
a2->setTag(1);
CCAction *a1 = m_tamara->runAction(CCRepeatForever::create ( seq2 ) );
a1->setTag(1);
CCAction *a = m_kathia->runAction(CCRepeatForever::create ( seq3 ) );
a->setTag(1);
schedule(schedule_selector(SpriteEase::testStopAction), 6.25f);
}
示例9: ccp
void GameLayer::playerChangeRoad(PlayerMoveDirection direction)
{
// check wether player can move to the new road
CCSprite *playerSprite = (CCSprite *)this->getChildByTag(PlayerTag);
CCPoint playerPos = playerSprite->getPosition();
if (direction == PlayerMoveLeft && playerPos.x < kGameMapSecondRoad) {
// already move to left
return;
}
if (direction == PlayerMoveRight && playerPos.x > kGameMapSecondRoad) {
// already move to right
return;
}
if (playerSprite->getActionByTag(PlayerChangeRoadTag)) {
return;
}
float distanceX = kGameMapRoadSpace;
CCGameMoveBy *moveBy = CCGameMoveBy::create(kPlayerChangeRoadDuration, ccp((direction == PlayerMoveLeft ? - distanceX : distanceX), kPlayerChangeRoadDuration * kPlayerRunSpeed));
CCAction *action = CCSequence::createWithTwoActions(moveBy, CCCallFunc::create(this, callfunc_selector(GameLayer::playerRun)));
action->setTag(PlayerChangeRoadTag);
if (isSliding) {
playerSprite->stopActionByTag(PlayerSlidingTag);
isSliding = false;
}
if (isJumpping) {
playerSprite->stopActionByTag(PlayerJumppingTag);
isJumpping = false;
}
isRunning = true;
playerSprite->runAction(action);
}
示例10: CCPointMake
void SpriteEase::onEnter()
{
EaseSpriteDemo::onEnter();
CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(350,0) );
CCActionInterval* move_back = move->reverse();
CCActionInterval* move_ease_in = (CCActionInterval*)CCEaseIn::actionWithAction((CCActionInterval*)(move->copy()->autorelease()), 3.0f);
CCActionInterval* move_ease_in_back = move_ease_in->reverse();
CCActionInterval* move_ease_out = CCEaseOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()), 3.0f);
CCActionInterval* move_ease_out_back = move_ease_out->reverse();
CCFiniteTimeAction* seq1 = CCSequence::actions(move, move_back, NULL);
CCFiniteTimeAction* seq2 = CCSequence::actions(move_ease_in, move_ease_in_back, NULL);
CCFiniteTimeAction* seq3 = CCSequence::actions(move_ease_out, move_ease_out_back, NULL);
CCAction *a2 = m_grossini->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq1) );
a2->setTag(1);
CCAction *a1 = m_tamara->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq2) );
a1->setTag(1);
CCAction *a = m_kathia->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq3) );
a->setTag(1);
schedule(schedule_selector(SpriteEase::testStopAction), 6);
}
示例11: CCPointMake
void SpriteEase::onEnter()
{
EaseSpriteDemo::onEnter();
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCActionInterval* move = CCMoveBy::create(3, CCPointMake(s.width-130,0));
CCActionInterval* move_back = move->reverse();
CCActionInterval* move_ease_in = CCEaseIn::create((CCActionInterval*)(move->copy()->autorelease()), 2.5f);
CCActionInterval* move_ease_in_back = move_ease_in->reverse();
CCActionInterval* move_ease_out = CCEaseOut::create((CCActionInterval*)(move->copy()->autorelease()), 2.5f);
CCActionInterval* move_ease_out_back = move_ease_out->reverse();
CCDelayTime *delay = CCDelayTime::create(0.25f);
CCFiniteTimeAction* seq1 = CCSequence::create(move, delay, move_back, CCCA(delay), NULL);
CCFiniteTimeAction* seq2 = CCSequence::create(move_ease_in, CCCA(delay), move_ease_in_back, CCCA(delay), NULL);
CCFiniteTimeAction* seq3 = CCSequence::create(move_ease_out, CCCA(delay), move_ease_out_back, CCCA(delay), NULL);
CCAction *a2 = m_grossini->runAction(CCRepeatForever::create((CCActionInterval*)seq1));
a2->setTag(1);
CCAction *a1 = m_tamara->runAction(CCRepeatForever::create((CCActionInterval*)seq2));
a1->setTag(1);
CCAction *a = m_kathia->runAction(CCRepeatForever::create((CCActionInterval*)seq3));
a->setTag(1);
schedule(schedule_selector(SpriteEase::testStopAction), 6.25f);
}
示例12: addChild
void GameScene::addPig()
{
const static int fameCount = 3;
const static float animationDuration = 0.15f;
CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
cache->addSpriteFramesWithFile("pigs.plist");
m_pPig = CCSprite::createWithSpriteFrameName("pig1");
m_pPig->retain();
m_pPig->setScale(0.7f);
m_pPig->setZOrder(1);
m_pPig->setPosition(ccp(m_VisibleOrigin.x + m_VisibleSize.width / 3, m_VisibleOrigin.y + m_VisibleSize.height / 2));
addChild(m_pPig);
CCArray *animFrames = CCArray::createWithCapacity(fameCount);
for(int i = 1; i <= fameCount; i++)
{
CCSpriteFrame* frame = cache->spriteFrameByName(CCString::createWithFormat("pig%d", i)->getCString());
animFrames->addObject(frame);
}
CCAction *action = CCRepeatForever::create(CCAnimate::create(CCAnimation::createWithSpriteFrames(animFrames, animationDuration)));
action->setTag(kTagFlutter);
m_pPig->runAction(action);
}
示例13: getParent
// 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 );
}
示例14: getActionByTag
void CCControlButton::setHighlighted(bool enabled)
{
if (enabled == true)
{
m_eState = CCControlStateHighlighted;
}
else
{
m_eState = CCControlStateNormal;
}
CCControl::setHighlighted(enabled);
CCAction *action = getActionByTag(kZoomActionTag);
if (action)
{
stopAction(action);
}
needsLayout();
if( m_zoomOnTouchDown )
{
float scaleValue = (isHighlighted() && isEnabled() && !isSelected()) ? 1.1f : 1.0f;
CCAction *zoomAction = CCScaleTo::create(0.05f, scaleValue);
zoomAction->setTag(kZoomActionTag);
runAction(zoomAction);
}
}
示例15: CCLOG
void ToTextLayer::RegistAA(){
if(e_layerstate == 1) return;
e_layerstate = 3;
CCLOG(">RegistAA");
stopActionByTag(AUTO_ACTION_TAG);
CCAction* au = CCSequence::create(CCDelayTime::create(m_fTAuto),CCCallFunc::create(this,callfunc_selector(ToTextLayer::AutoNext)),NULL);
au->setTag(AUTO_ACTION_TAG);
runAction(au);
}