//------------------------------------------------------------------ // // SpriteProgressToRadialMidpointChanged // //------------------------------------------------------------------ void SpriteProgressToRadialMidpointChanged::onEnter() { SpriteDemo::onEnter(); CCSize s = CCDirector::sharedDirector()->getWinSize(); CCProgressTo *action = CCProgressTo::create(2, 100); /** * Our image on the left should be a radial progress indicator, clockwise */ CCProgressTimer *left = CCProgressTimer::create(CCSprite::create(s_pPathBlock)); left->setType(kCCProgressTimerTypeRadial); addChild(left); left->setMidpoint(ccp(0.25f, 0.75f)); left->setPosition(ccp(100, s.height/2)); left->runAction(CCRepeatForever::create((CCActionInterval *)action->copy()->autorelease())); /** * Our image on the left should be a radial progress indicator, counter clockwise */ CCProgressTimer *right = CCProgressTimer::create(CCSprite::create(s_pPathBlock)); right->setType(kCCProgressTimerTypeRadial); right->setMidpoint(ccp(0.75f, 0.25f)); /** * Note the reverse property (default=NO) is only added to the right image. That's how * we get a counter clockwise progress. */ addChild(right); right->setPosition(ccp(s.width-100, s.height/2)); right->runAction(CCRepeatForever::create((CCActionInterval *)action->copy()->autorelease())); }
CCProgressTo* CCProgressTo::create(float duration, float fPercent) { CCProgressTo *pProgressTo = new CCProgressTo(); pProgressTo->initWithDuration(duration, fPercent); pProgressTo->autorelease(); return pProgressTo; }
CCProgressTo* CCProgressTo::actionWithDuration(ccTime duration, float fPercent) { CCProgressTo *pProgressTo = new CCProgressTo(); pProgressTo->initWithDuration(duration, fPercent); pProgressTo->autorelease(); return pProgressTo; }
//------------------------------------------------------------------ // // SpriteProgressBarTintAndFade // //------------------------------------------------------------------ void SpriteProgressBarTintAndFade::onEnter() { SpriteDemo::onEnter(); CCSize s = CCDirector::sharedDirector()->getWinSize(); CCProgressTo *to = CCProgressTo::create(6, 100); CCAction *tint = CCSequence::create(CCTintTo::create(1, 255, 0, 0), CCTintTo::create(1, 0, 255, 0), CCTintTo::create(1, 0, 0, 255), NULL); CCAction *fade = CCSequence::create(CCFadeTo::create(1.0f, 0), CCFadeTo::create(1.0f, 255), NULL); CCProgressTimer *left = CCProgressTimer::create(CCSprite::create(s_pPathSister1)); left->setType(kCCProgressTimerTypeBar); // Setup for a bar starting from the bottom since the midpoint is 0 for the y left->setMidpoint(ccp(0.5f, 0.5f)); // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change left->setBarChangeRate(ccp(1, 0)); addChild(left); left->setPosition(ccp(100, s.height/2)); left->runAction(CCRepeatForever::create((CCActionInterval *)to->copy()->autorelease())); left->runAction(CCRepeatForever::create((CCActionInterval *)tint->copy()->autorelease())); left->addChild(CCLabelTTF::create("Tint", "Marker Felt", 20.0f)); CCProgressTimer *middle = CCProgressTimer::create(CCSprite::create(s_pPathSister2)); middle->setType(kCCProgressTimerTypeBar); // Setup for a bar starting from the bottom since the midpoint is 0 for the y middle->setMidpoint(ccp(0.5f, 0.5f)); // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change middle->setBarChangeRate(ccp(1, 1)); addChild(middle); middle->setPosition(ccp(s.width/2, s.height/2)); middle->runAction(CCRepeatForever::create((CCActionInterval *)to->copy()->autorelease())); middle->runAction(CCRepeatForever::create((CCActionInterval *)fade->copy()->autorelease())); middle->addChild(CCLabelTTF::create("Fade", "Marker Felt", 20.0f)); CCProgressTimer *right = CCProgressTimer::create(CCSprite::create(s_pPathSister2)); right->setType(kCCProgressTimerTypeBar); // Setup for a bar starting from the bottom since the midpoint is 0 for the y right->setMidpoint(ccp(0.5f, 0.5f)); // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change right->setBarChangeRate(ccp(0, 1)); addChild(right); right->setPosition(ccp(s.width-100, s.height/2)); right->runAction(CCRepeatForever::create((CCActionInterval *)to->copy()->autorelease())); right->runAction(CCRepeatForever::create((CCActionInterval *)tint->copy()->autorelease())); right->runAction(CCRepeatForever::create((CCActionInterval *)fade->copy()->autorelease())); right->addChild(CCLabelTTF::create("Tint and Fade", "Marker Felt", 20.0f)); }
NS_CC_BEGIN // implementation of CCProgressTo CCProgressTo* CCProgressTo::create(float duration, float fPercent) { CCProgressTo *pProgressTo = new CCProgressTo(); pProgressTo->initWithDuration(duration, fPercent); pProgressTo->autorelease(); return pProgressTo; }
NS_CC_BEGIN #define kProgressTimerCast CCProgressTimer* // implementation of CCProgressTo // 实现进度 CCProgressTo* CCProgressTo::create(float duration, float fPercent) { CCProgressTo *pProgressTo = new CCProgressTo(); pProgressTo->initWithDuration(duration, fPercent); pProgressTo->autorelease(); return pProgressTo; }
//------------------------------------------------------------------ // // SpriteProgressWithSpriteFrame // //------------------------------------------------------------------ void SpriteProgressWithSpriteFrame::onEnter() { SpriteDemo::onEnter(); CCSize s = CCDirector::sharedDirector()->getWinSize(); CCProgressTo *to = CCProgressTo::create(6, 100); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("zwoptex/grossini.plist"); CCProgressTimer *left = CCProgressTimer::create(CCSprite::createWithSpriteFrameName("grossini_dance_01.png")); left->setType(kCCProgressTimerTypeBar); // Setup for a bar starting from the bottom since the midpoint is 0 for the y left->setMidpoint(ccp(0.5f, 0.5f)); // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change left->setBarChangeRate(ccp(1, 0)); addChild(left); left->setPosition(ccp(100, s.height/2)); left->runAction(CCRepeatForever::create((CCActionInterval *)to->copy()->autorelease())); CCProgressTimer *middle = CCProgressTimer::create(CCSprite::createWithSpriteFrameName("grossini_dance_02.png")); middle->setType(kCCProgressTimerTypeBar); // Setup for a bar starting from the bottom since the midpoint is 0 for the y middle->setMidpoint(ccp(0.5f, 0.5f)); // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change middle->setBarChangeRate(ccp(1, 1)); addChild(middle); middle->setPosition(ccp(s.width/2, s.height/2)); middle->runAction(CCRepeatForever::create((CCActionInterval *)to->copy()->autorelease())); CCProgressTimer *right = CCProgressTimer::create(CCSprite::createWithSpriteFrameName("grossini_dance_03.png")); right->setType(kCCProgressTimerTypeRadial); // Setup for a bar starting from the bottom since the midpoint is 0 for the y right->setMidpoint(ccp(0.5f, 0.5f)); // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change right->setBarChangeRate(ccp(0, 1)); addChild(right); right->setPosition(ccp(s.width-100, s.height/2)); right->runAction(CCRepeatForever::create((CCActionInterval *)to->copy()->autorelease())); }
//------------------------------------------------------------------ // // SpriteProgressBarVarious // //------------------------------------------------------------------ void SpriteProgressBarVarious::onEnter() { SpriteDemo::onEnter(); CCSize s = CCDirector::sharedDirector()->getWinSize(); CCProgressTo *to = CCProgressTo::create(2, 100); CCProgressTimer *left = CCProgressTimer::create(CCSprite::create(s_pPathSister1)); left->setType(kCCProgressTimerTypeBar); // Setup for a bar starting from the bottom since the midpoint is 0 for the y left->setMidpoint(ccp(0.5f, 0.5f)); // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change left->setBarChangeRate(ccp(1, 0)); addChild(left); left->setPosition(ccp(100, s.height/2)); left->runAction(CCRepeatForever::create((CCActionInterval *)to->copy()->autorelease())); CCProgressTimer *middle = CCProgressTimer::create(CCSprite::create(s_pPathSister2)); middle->setType(kCCProgressTimerTypeBar); // Setup for a bar starting from the bottom since the midpoint is 0 for the y middle->setMidpoint(ccp(0.5f, 0.5f)); // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change middle->setBarChangeRate(ccp(1,1)); addChild(middle); middle->setPosition(ccp(s.width/2, s.height/2)); middle->runAction(CCRepeatForever::create((CCActionInterval *)to->copy()->autorelease())); CCProgressTimer *right = CCProgressTimer::create(CCSprite::create(s_pPathSister2)); right->setType(kCCProgressTimerTypeBar); // Setup for a bar starting from the bottom since the midpoint is 0 for the y right->setMidpoint(ccp(0.5f, 0.5f)); // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change right->setBarChangeRate(ccp(0, 1)); addChild(right); right->setPosition(ccp(s.width-100, s.height/2)); right->runAction(CCRepeatForever::create((CCActionInterval *)to->copy()->autorelease())); }
CCObject* CCProgressTo::copyWithZone(CCZone *pZone) { CCZone* pNewZone = NULL; CCProgressTo* pCopy = NULL; if(pZone && pZone->m_pCopyObject) { //in case of being called at sub class pCopy = (CCProgressTo*)(pZone->m_pCopyObject); } else { pCopy = new CCProgressTo(); pZone = pNewZone = new CCZone(pCopy); } CCActionInterval::copyWithZone(pZone); pCopy->initWithDuration(m_fDuration, m_fTo); CC_SAFE_DELETE(pNewZone); return pCopy; }