|
| 1 | +// not taken from https://github.com/acaruso-xx/slope-geode/blob/main/src/plate/LoadingCircle.cpp |
| 2 | +#include "RLLoadingCircle.hpp" |
| 3 | + |
| 4 | +RLLoadingCircle* RLLoadingCircle::create() |
| 5 | +{ |
| 6 | + auto ret = new RLLoadingCircle(); |
| 7 | + |
| 8 | + if (ret && ret->init()) |
| 9 | + ret->autorelease(); |
| 10 | + else |
| 11 | + { |
| 12 | + delete ret; |
| 13 | + ret = nullptr; |
| 14 | + } |
| 15 | + |
| 16 | + return ret; |
| 17 | +} |
| 18 | + |
| 19 | +bool RLLoadingCircle::init() |
| 20 | +{ |
| 21 | + if (!this->initWithFile("loadingCircle.png")) return false; |
| 22 | + |
| 23 | + this->setBlendFunc({ GL_SRC_ALPHA, GL_ONE }); |
| 24 | + this->setOpacity(0); |
| 25 | + this->setZOrder(105); |
| 26 | + |
| 27 | + return true; |
| 28 | +} |
| 29 | + |
| 30 | +void RLLoadingCircle::positionCenter() |
| 31 | +{ |
| 32 | + this->setPosition(cocos2d::CCDirector::sharedDirector()->getWinSize() / 2); |
| 33 | +} |
| 34 | + |
| 35 | +void RLLoadingCircle::fadeIn() |
| 36 | +{ |
| 37 | + auto* fadeInAction = cocos2d::CCFadeTo::create(.4f, 200); |
| 38 | + fadeInAction->setTag(ACTION_TAG::FADE_IN); |
| 39 | + |
| 40 | + this->runAction(fadeInAction); |
| 41 | +} |
| 42 | + |
| 43 | +void RLLoadingCircle::fadeOut() |
| 44 | +{ |
| 45 | + this->stopActionByTag(ACTION_TAG::FADE_IN); |
| 46 | + this->stopActionByTag(ACTION_TAG::ROTATE); |
| 47 | + |
| 48 | + auto* fadeOutAction = cocos2d::CCFadeTo::create(.4f, 0); |
| 49 | + fadeOutAction->setTag(ACTION_TAG::FADE_OUT); |
| 50 | + |
| 51 | + this->runAction(fadeOutAction); |
| 52 | +} |
| 53 | + |
| 54 | +void RLLoadingCircle::startRotate() |
| 55 | +{ |
| 56 | + auto* rotateAction = cocos2d::CCRepeatForever::create( |
| 57 | + cocos2d::CCRotateBy::create(1.f, 360.f) |
| 58 | + ); |
| 59 | + rotateAction->setTag(ACTION_TAG::ROTATE); |
| 60 | + |
| 61 | + this->runAction(rotateAction); |
| 62 | +} |
| 63 | + |
| 64 | +void RLLoadingCircle::stopRotate() |
| 65 | +{ |
| 66 | + this->stopActionByTag(ACTION_TAG::ROTATE); |
| 67 | +} |
| 68 | + |
| 69 | +void RLLoadingCircle::show() |
| 70 | +{ |
| 71 | + fadeIn(); |
| 72 | + startRotate(); |
| 73 | +} |
| 74 | + |
| 75 | +void RLLoadingCircle::stopAndHide() |
| 76 | +{ |
| 77 | + stopRotate(); |
| 78 | + fadeOut(); |
| 79 | +} |
0 commit comments