12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539 |
- #include "REDAnimationManager.h"
- #include "CCNodeLoader.h"
- #include "REDReader.h"
- #include "CCNode+REDRelativePositioning.h"
- #include "audio/include/AudioEngine.h"
- #include "REDSelectorResolver.h"
- #include <spine/spine-cocos2dx.h>
- #include <string>
- #include <sstream>
- #include <set>
- #include "common/CocosConfig.h"
- #include "BezierEqualPointsAction.hpp"
- #include "REDActionInstant.h"
- #include "RedWise.hpp"
- using namespace cocos2d;
- using namespace std;
- using namespace cocos2d::extension;
- using namespace experimental;
- namespace redream {
- // Implementation of REDAinmationManager
- #define LE_CHR(a,b,c,d) ( ((a)<<24) | ((b)<<16) | ((c)<<8) | (d) )
-
- static int animationTag = LE_CHR('c','c','b','i');
- REDAnimationManager::REDAnimationManager()
- : _owner(nullptr)
- , _autoPlaySequenceId(0)
- , _rootNode(nullptr)
- , _rootContainerSize(Size::ZERO)
- , _delegate(nullptr)
- , _runningSequence(std::make_pair(nullptr, nullptr))
- , _speed(1.0f)
- , _listen(nullptr)
- , _lastTag(0)
- , _nowTag(0)
- {
- init();
- }
- REDAnimationManager *REDAnimationManager::fromNode(Node *node)
- {
- return dynamic_cast<REDAnimationManager*>(node->getUserObject());
- }
- bool REDAnimationManager::init()
- {
- _target = nullptr;
- _animationCompleteCallbackFunc = nullptr;
-
- return true;
- }
- REDAnimationManager::~REDAnimationManager()
- {
- // DictElement *pElement = nullptr;
- // CCDICT_FOREACH(_nodeSequences, pElement)
- // {
- // Node *node = (Node*)pElement->getIntKey();
- // node->release();
- // }
- //
- // CCDICT_FOREACH(_baseValues, pElement)
- // {
- // Node *node = (Node*)pElement->getIntKey();
- // node->release();
- // }
- if (_rootNode)
- {
- _rootNode->stopAllActions();
- }
- if (!_needResetSpriteFrames.empty()) {
- _needResetSpriteFrames.clear();
- }
- setRootNode(nullptr);
- setDelegate(nullptr);
-
- for (auto iter = _objects.begin(); iter != _objects.end(); ++iter)
- {
- for (auto iter2 = iter->second.begin(); iter2 != iter->second.end(); ++iter2)
- {
- iter2->second->release();
- }
- }
-
- CC_SAFE_RELEASE(_target);
- }
- Vector<REDSequence*>& REDAnimationManager::getSequences()
- {
- return _sequences;
- }
- void REDAnimationManager::setSequences(const Vector<REDSequence*>& seq)
- {
- _sequences = seq;
- }
- int REDAnimationManager::getAutoPlaySequenceId()
- {
- return _autoPlaySequenceId;
- }
- void REDAnimationManager::setAutoPlaySequenceId(int autoPlaySequenceId)
- {
- _autoPlaySequenceId = autoPlaySequenceId;
- }
- Node* REDAnimationManager::getRootNode()
- {
- return _rootNode;
- }
- void REDAnimationManager::setRootNode(Node *pRootNode)
- {
- _rootNode = pRootNode;
- }
- void REDAnimationManager::setDocumentControllerName(const std::string &name)
- {
- _documentControllerName = name;
- }
- std::string REDAnimationManager::getDocumentControllerName()
- {
- return _documentControllerName;
- }
- void REDAnimationManager::addDocumentCallbackNode(Node *node)
- {
- _documentCallbackNodes.pushBack(node);
- }
- void REDAnimationManager::addDocumentCallbackName(std::string name)
- {
- _documentCallbackNames.push_back(Value(name));
- }
- void REDAnimationManager::addDocumentCallbackControlEvents(Control::EventType eventType)
- {
- _documentCallbackControlEvents.push_back(Value(static_cast<int>(eventType)));
- }
- ValueVector& REDAnimationManager::getDocumentCallbackNames()
- {
- return _documentCallbackNames;
- }
- Vector<Node*>& REDAnimationManager::getDocumentCallbackNodes()
- {
- return _documentCallbackNodes;
- }
- ValueVector& REDAnimationManager::getDocumentCallbackControlEvents()
- {
- return _documentCallbackControlEvents;
- }
- void REDAnimationManager::addDocumentOutletNode(Node *node)
- {
- _documentOutletNodes.pushBack(node);
- }
- void REDAnimationManager::addDocumentOutletName(std::string name)
- {
- _documentOutletNames.push_back(Value(name));
- }
- ValueVector& REDAnimationManager::getDocumentOutletNames()
- {
- return _documentOutletNames;
- }
- Vector<Node*>& REDAnimationManager::getDocumentOutletNodes()
- {
- return _documentOutletNodes;
- }
- std::string REDAnimationManager::getLastCompletedSequenceName()
- {
- return _lastCompletedSequenceName;
- }
- ValueVector& REDAnimationManager::getKeyframeCallbacks()
- {
- return _keyframeCallbacks;
- }
- const Size& REDAnimationManager::getRootContainerSize()
- {
- return _rootContainerSize;
- }
- void REDAnimationManager::setRootContainerSize(const Size &rootContainerSize)
- {
- _rootContainerSize.setSize(rootContainerSize.width, rootContainerSize.height);
- }
- REDAnimationManagerDelegate* REDAnimationManager::getDelegate()
- {
- return _delegate;
- }
- void REDAnimationManager::setDelegate(REDAnimationManagerDelegate *pDelegate)
- {
- CC_SAFE_RELEASE(dynamic_cast<Ref*>(_delegate));
- _delegate = pDelegate;
- CC_SAFE_RETAIN(dynamic_cast<Ref*>(_delegate));
- }
- const char* REDAnimationManager::getRunningSequenceName()
- {
- if (_runningSequence.first)
- {
- return _runningSequence.first->getName();
- }
- return nullptr;
- }
- const Size& REDAnimationManager::getContainerSize(Node *pNode)
- {
- if (pNode)
- {
- return pNode->getContentSize();
- }
- else
- {
- return _rootContainerSize;
- }
- }
- // refer to REDReader::readNodeGraph() for data structure of pSeq
- void REDAnimationManager::addNode(Node *pNode, const std::unordered_map<int, Map<std::string, REDSequenceProperty*>>& seq)
- {
- // pNode->retain();
-
- _nodeSequences[pNode] = seq;
- }
- void REDAnimationManager::setBaseValue(const Value& value, Node *pNode, const std::string& propName)
- {
- auto& props = _baseValues[pNode];
- props[propName] = value;
- }
- const Value& REDAnimationManager::getBaseValue(Node *pNode, const std::string& propName)
- {
- auto& props = _baseValues[pNode];
- return props[propName];
- }
-
- void REDAnimationManager::setObject(Ref* obj, Node *pNode, const std::string& propName)
- {
- auto& props = _objects[pNode];
- auto iter = props.find(propName);
- if (iter != props.end())
- iter->second->release();
-
- props[propName] = obj;
- obj->retain();
- }
- Ref* REDAnimationManager::getObject(Node *pNode, const std::string& propName)
- {
- auto& props = _objects[pNode];
- auto iter = props.find(propName);
- if (iter != props.end())
- return iter->second;
-
- return nullptr;
- }
- int REDAnimationManager::getSequenceId(const char* pSequenceName)
- {
- string seqName(pSequenceName);
- for (auto& seq : _sequences)
- {
- if (seqName.compare(seq->getName()) == 0)
- {
- return seq->getSequenceId();
- }
- }
- return -1;
- }
- REDSequence* REDAnimationManager::getSequence(int nSequenceId)
- {
- for (auto& seq : _sequences)
- {
- if (seq->getSequenceId() == nSequenceId)
- {
- return seq;
- }
- }
- return nullptr;
- }
- float REDAnimationManager::getSequenceDuration(const char *pSequenceName)
- {
- int id = getSequenceId(pSequenceName);
- if (id != -1)
- return getSequence(id)->getDuration();
- return 0;
- }
- std::string REDAnimationManager::getREDFileName(){
- return _ccbFileName;
- }
- void REDAnimationManager::setREDFileName(std::string filename){
- _ccbFileName = filename;
- }
- void REDAnimationManager::moveAnimationsFromNode(Node* fromNode, Node* toNode)
- {
- // Move base values
- auto baseValueIter = _baseValues.find(fromNode);
- if(baseValueIter != _baseValues.end())
- {
- _baseValues[toNode] = baseValueIter->second;
- _baseValues.erase(baseValueIter);
- // fromNode->release();
- // toNode->retain();
- }
-
- auto objIter = _objects.find(fromNode);
- if (objIter != _objects.end())
- {
- _objects[toNode] = objIter->second;
- _objects.erase(objIter);
- }
-
-
- // Move seqs
- auto seqsIter = _nodeSequences.find(fromNode);
- if (seqsIter != _nodeSequences.end())
- {
- _nodeSequences[toNode] = seqsIter->second;
- _nodeSequences.erase(seqsIter);
- // fromNode->release();
- // toNode->retain();
- }
- }
- // Refer to REDReader::readKeyframe() for the real type of value
- ActionInterval* REDAnimationManager::getAction(REDKeyframe *pKeyframe0, REDKeyframe *pKeyframe1, const std::string& propName, Node *pNode)
- {
- float duration = pKeyframe1->getTime() - (pKeyframe0 ? pKeyframe0->getTime() : 0);
-
- if (propName == "rotationX")
- {
- return REDRotateXTo::create(duration, pKeyframe1->getValue().asFloat());
- }
- else if (propName == "rotationY")
- {
- return REDRotateYTo::create(duration, pKeyframe1->getValue().asFloat());
- }
- else if (propName == "rotation")
- {
- return REDRotateTo::create(duration, pKeyframe1->getValue().asFloat());
- }
- else if (propName == "opacity")
- {
- return FadeTo::create(duration, pKeyframe1->getValue().asByte());
- }
- else if (propName == "color")
- {
- auto c = pKeyframe1->getValue().asValueMap();
- unsigned char r = c["r"].asByte();
- unsigned char g = c["g"].asByte();
- unsigned char b = c["b"].asByte();
- return TintTo::create(duration, r, g, b);
- }
- else if (propName == "visible")
- {
- if (pKeyframe1->getValue().asBool())
- {
- return Sequence::createWithTwoActions(DelayTime::create(duration), Show::create());
- }
- else
- {
- return Sequence::createWithTwoActions(DelayTime::create(duration), Hide::create());
- }
- }
- else if (propName == "displayFrame")
- {
- return Sequence::createWithTwoActions(DelayTime::create(duration),
- REDSetSpriteFrame::create(static_cast<SpriteFrame*>(pKeyframe1->getObject())));
- }
- else if (propName == "position")
- {
- /*
- // Get position type
- auto& array = getBaseValue(pNode, propName).asValueVector();
- REDReader::PositionType type = (REDReader::PositionType)array[2].asInt();
-
- // Get relative position
- auto value = pKeyframe1->getValue().asValueVector();
- float x = value[0].asFloat();
- float y = value[1].asFloat();
-
- Size containerSize = getContainerSize(pNode->getParent());
-
- Vec2 absPos = getAbsolutePosition(Vec2(x,y), type, containerSize, propName);
-
- return MoveTo::create(duration, absPos);*/
- auto& array = getBaseValue(pNode, propName).asValueVector();
- PositionReferenceCorner corner = (PositionReferenceCorner)array[2].asInt();
- PositionUnit xUnit = (PositionUnit)array[3].asInt();
- PositionUnit yUnit = (PositionUnit)array[4].asInt();
-
- // Get relative position
- auto value = pKeyframe1->getValue().asValueVector();
- float x = value[0].asFloat();
- float y = value[1].asFloat();
-
- Size containerSize = getContainerSize(pNode->getParent());
-
- Vec2 absPos = getAbsolutePosition(1.0f, 1.0f, Vec2(x,y), corner, xUnit, yUnit, containerSize);
-
- // return MoveTo::create(duration, absPos);
-
- std::vector<Vec2> equalPoints = pKeyframe0->getEqualPoints();
- std::vector<Vec2> newEqualPoints = {};
- for (Vec2 point : equalPoints) {
- Vec2 newPoint = getAbsolutePosition(1.0f, 1.0f, point, corner, xUnit, yUnit, containerSize);
- newEqualPoints.push_back(newPoint);
- }
- if (!newEqualPoints.empty()) { // 有贝塞尔信息
- return BezierEqualPointsAction::create(duration, newEqualPoints);
- } else { // 没有贝塞尔信息,直线运动
- return MoveTo::create(duration, absPos);
- }
- }
- else if (propName == "scale")
- {
- // Get position type
- auto& array = getBaseValue(pNode, propName).asValueVector();
- REDReader::ScaleType type = (REDReader::ScaleType)array[2].asInt();
-
- // Get relative scale
- auto value = pKeyframe1->getValue().asValueVector();
- float x = value[0].asFloat();
- float y = value[1].asFloat();
-
- if (type == REDReader::ScaleType::MULTIPLY_RESOLUTION)
- {
- float resolutionScale = REDReader::getResolutionScale();
- x *= resolutionScale;
- y *= resolutionScale;
- }
-
- return ScaleTo::create(duration, x, y);
- }
- else if (propName == "skew")
- {
- // Get relative skew
- auto& value = pKeyframe1->getValue().asValueVector();
- float x = value[0].asFloat();
- float y = value[1].asFloat();
-
- return SkewTo::create(duration, x, y);
- }else if (propName == "frame")
- {
- auto value0 = pKeyframe1->getValue().asValueMap();
- std::string anim = value0["animation"].asString();
- bool loop = value0["loop"].asBool();
- spine::SkeletonFrame frame;
- frame.animation = anim;
- frame.progress = 0.0f;
- frame.loop = loop;
-
- return Sequence::createWithTwoActions(DelayTime::create(duration), spine::SpineActionInstant::create(frame));
-
- //TODO
- // log("REDReader: TODO implement the spine action !!!");
- }else if (propName == "animation")
- {
- // Get sequence id
- int value = pKeyframe1->getValue().asInt();
- return Sequence::createWithTwoActions(DelayTime::create(duration), REDAnimation::create(value));
- }
- else if (propName == "frameIndex")
- {
- return REDFrameIndexTo::create(duration, pKeyframe0->getValue().asByte(), pKeyframe1->getValue().asByte());
- }
- else if (propName == "posVar"){
- //粒子发射器大小
- auto& value = pKeyframe1->getValue().asValueVector();
- float x = value[0].asFloat();
- float y = value[1].asFloat();
- return REDParticlePosVarTo::create(duration, Vec2(x,y));
- }
- else if (propName == "gravity"){
- // 粒子重力
- auto& value = pKeyframe1->getValue().asValueVector();
- float x = value[0].asFloat();
- float y = value[1].asFloat();
- return REDGravityTo::create(duration, Vec2(x,y));
- }
- else if(propName == "speed"){
- // 粒子速度
- auto& value = pKeyframe1->getValue().asValueVector();
- float x = value[0].asFloat();
- float y = value[1].asFloat();
- return REDParticleSpeedTo::create(duration, Vec2(x,y));
- }
- else if(propName == "life"){
- // 粒子生命
- auto& value = pKeyframe1->getValue().asValueVector();
- float x = value[0].asFloat();
- float y = value[1].asFloat();
- return REDParticleLifeTo::create(duration, Vec2(x,y));
- }
- else if(propName == "startSize"){
- // 初始尺寸
- auto& value = pKeyframe1->getValue().asValueVector();
- float x = value[0].asFloat();
- float y = value[1].asFloat();
- return REDParticleStartSizeTo::create(duration, Vec2(x,y));
- }
- else if(propName == "endSize"){
- // 结束尺寸
- auto& value = pKeyframe1->getValue().asValueVector();
- float x = value[0].asFloat();
- float y = value[1].asFloat();
- return REDParticleEndSizeTo::create(duration, Vec2(x,y));
- }
- else if(propName == "startSpin"){
- // 开始旋转角度:
- auto& value = pKeyframe1->getValue().asValueVector();
- float x = value[0].asFloat();
- float y = value[1].asFloat();
- return REDParticleStartSpinTo::create(duration, Vec2(x,y));
- }
- else if(propName == "endSpin"){
- // 结束旋转角度
- auto& value = pKeyframe1->getValue().asValueVector();
- float x = value[0].asFloat();
- float y = value[1].asFloat();
- return REDParticleEndSpinTo::create(duration, Vec2(x,y));
- }
- else if(propName == "angle"){
- // 发射角度
- auto& value = pKeyframe1->getValue().asValueVector();
- float x = value[0].asFloat();
- float y = value[1].asFloat();
- return REDParticleAngleTo::create(duration, Vec2(x,y));
- }
- else if(propName == "tangentialAccel"){
- // 切向加速度
- auto& value = pKeyframe1->getValue().asValueVector();
- float x = value[0].asFloat();
- float y = value[1].asFloat();
- return REDParticleTangentialAccelTo::create(duration, Vec2(x,y));
- }
- else if(propName == "radialAccel"){
- // 径向加速度:
- auto& value = pKeyframe1->getValue().asValueVector();
- float x = value[0].asFloat();
- float y = value[1].asFloat();
- return REDParticleRadialAccelTo::create(duration, Vec2(x,y));
- }
- else if(propName == "startRadius"){
- // 开始半径:
- auto& value = pKeyframe1->getValue().asValueVector();
- float x = value[0].asFloat();
- float y = value[1].asFloat();
- return REDParticleStartRadiusTo::create(duration, Vec2(x,y));
- }
- else if(propName == "endRadius"){
- // 结束半径
- auto& value = pKeyframe1->getValue().asValueVector();
- float x = value[0].asFloat();
- float y = value[1].asFloat();
- return REDParticleEndRadiusTo::create(duration, Vec2(x,y));
- }
- else if(propName == "rotatePerSecond"){
- // 旋转:
- auto& value = pKeyframe1->getValue().asValueVector();
- float x = value[0].asFloat();
- float y = value[1].asFloat();
- return REDParticleRotatePerSecondTo::create(duration, Vec2(x,y));
- }
- else if(propName == "enabled"){
- if (pKeyframe1->getValue().asBool()) {
- return Sequence::createWithTwoActions(DelayTime::create(duration), Enable::create());
- } else {
- return Sequence::createWithTwoActions(DelayTime::create(duration), Disable::create());
- }
- }
- else if(propName == "string"){
- std::string text = pKeyframe1->getValue().asString();
- return Sequence::createWithTwoActions(DelayTime::create(duration), REDLabelString::actionWithText(text));
- }
- else if (propName == "useMaterial") {
- if (pKeyframe1->getValue().asBool()) {
- return Sequence::createWithTwoActions(DelayTime::create(duration), EnableMaterial::create());
- } else {
- return Sequence::createWithTwoActions(DelayTime::create(duration), DisableMaterial::create());
- }
- }
- else if (propName == "bakeAnimation") {
- RedBakeNodeFrame frame;
- frame.animationName = pKeyframe1->getValue().asValueVector()[0].asString();
- frame.elapsedTime = 0;
- frame.loop = pKeyframe1->getValue().asValueVector()[2].asBool();;
- return Sequence::createWithTwoActions(DelayTime::create(duration), RedBakeAnimationInstantAction::create(frame));
- }
- else
- {
- log("REDReader: Failed to create animation for property: %s", propName.c_str());
- }
-
- return nullptr;
- }
- void REDAnimationManager::setAnimatedProperty(const std::string& propName, Node *pNode, const Value& value, Ref* obj, float fTweenDuration, bool isBaseValue)
- {
- if (fTweenDuration > 0)
- {
- // Create a fake keyframe to generate the action from
- REDKeyframe *kf1 = new (std::nothrow) REDKeyframe();
- kf1->autorelease();
-
- kf1->setObject(obj);
- kf1->setValue(value);
- kf1->setTime(fTweenDuration);
- kf1->setEasingType(REDKeyframe::EasingType::LINEAR);
-
- // Animate
- ActionInterval *tweenAction = getAction(nullptr, kf1, propName, pNode);
- pNode->runAction(tweenAction);
- }
- else
- {
- // Just set the value
-
- if (propName == "position")
- {
- /*
- // Get position type
- auto& array = getBaseValue(pNode, propName).asValueVector();
- REDReader::PositionType type = (REDReader::PositionType)array[2].asInt();
- // Get relative position
- auto& valueVector = value.asValueVector();
- float x = valueVector[0].asFloat();
- float y = valueVector[1].asFloat();
-
- pNode->setPosition(getAbsolutePosition(Vec2(x,y), type, getContainerSize(pNode->getParent()), propName));
- pNode->setPosition(getAbsolutePosition(Vec2(x,y), type, getContainerSize(pNode->getParent()), propName));*/
-
- // Get position type
- auto& array = getBaseValue(pNode, propName).asValueVector();
- PositionReferenceCorner corner = (PositionReferenceCorner)array[2].asInt();
- PositionUnit xUnit = (PositionUnit)array[3].asInt();
- PositionUnit yUnit = (PositionUnit)array[4].asInt();
-
- // Get relative position
- auto& valueVector = value.asValueVector();
- float x = valueVector[0].asFloat();
- float y = valueVector[1].asFloat();
-
- pNode->setPosition(getAbsolutePosition(1.0f, 1.0f, Vec2(x,y), corner, xUnit, yUnit, getContainerSize(pNode->getParent())));
- }
- else if (propName == "scale")
- {
- // Get scale type
- auto& array = getBaseValue(pNode, propName).asValueVector();
- REDReader::ScaleType type = (REDReader::ScaleType)array[2].asInt();
-
- // Get relative scale
- auto& valueVector = value.asValueVector();
- float x = valueVector[0].asFloat();
- float y = valueVector[1].asFloat();
-
- setRelativeScale(pNode, x, y, type, propName);
- }
- else if(propName == "skew")
- {
- // Get relative scale
- auto& valueVector = value.asValueVector();
- float x = valueVector[0].asFloat();
- float y = valueVector[1].asFloat();
- pNode->setSkewX(x);
- pNode->setSkewY(y);
- }
- else if (propName == "animation")
- {
- int sequenceId = value.asInt();
- REDAnimationManager *animationManager = REDAnimationManager::fromNode(pNode);
- if(animationManager)
- {
- if(sequenceId == -2 || sequenceId == -1)
- animationManager->refreshStatusOnFirstFream(animationManager->getAutoPlaySequenceId(), 0);
- else
- animationManager->refreshStatusOnFirstFream(sequenceId, 0);
- }
-
- }
- else if (propName == "frame")
- {
- auto frame = value.asValueMap();
- std::string anim = frame["animation"].asString();
-
- auto node = static_cast<spine::SkeletonAnimation*>(pNode);
-
- if(strcmp(anim.c_str(), "Null") == 0 || strcmp(anim.c_str(), "") == 0){
- node->setEmptyAnimations(0);
- node->update(0);
- } else {
- node->clearTrack();
- node->setAnimation(0, anim, false);
- node->update(0);
- node->clearTrack();
- }
- }
- else
- {
- // [node setValue:value forKey:name];
- // TODO: only handle rotation, opacity, displayFrame, color
- if (propName == "rotation")
- {
- float rotate = value.asFloat();
- pNode->setRotation(rotate);
- } else if(propName == "rotationX")
- {
- float rotate = value.asFloat();
- pNode->setRotationSkewX(rotate);
- }else if(propName == "rotationY")
- {
- float rotate = value.asFloat();
- pNode->setRotationSkewY(rotate);
- }
- else if (propName == "opacity")
- {
- unsigned char opacity = value.asByte();
- pNode->setOpacity(opacity);
- }
- else if (propName == "displayFrame")
- {
- static_cast<Sprite*>(pNode)->setSpriteFrame(static_cast<SpriteFrame*>(obj));
- }
- else if (propName == "color")
- {
- auto c = value.asValueMap();
- unsigned char r = c["r"].asByte();
- unsigned char g = c["g"].asByte();
- unsigned char b = c["b"].asByte();
- pNode->setColor(Color3B(r, g, b));
- }
- else if (propName == "visible")
- {
- bool visible = value.asBool();
- pNode->setVisible(visible);
- }
- else if (propName == "frameIndex") {
- unsigned char frameIndex = value.asByte();
- static_cast<ZGFrameActionSprite*>(pNode)->setFrameIndex(frameIndex);
- }
- else if (propName == "posVar"){
- // 粒子发射器尺寸
- auto& valueVector = value.asValueVector();
- float gx = valueVector[0].asFloat();
- float gy = valueVector[1].asFloat();
- static_cast<ZMLCCParticleSystem*>(pNode)->setPosVar(Vec2(gx, gy));
- }
- else if (propName == "gravity") {
- // 粒子重力
- auto& valueVector = value.asValueVector();
- float gx = valueVector[0].asFloat();
- float gy = valueVector[1].asFloat();
- static_cast<ZMLCCParticleSystem*>(pNode)->setGravity(Vec2(gx, gy));
- }
- else if (propName == "speed") {
- // 粒子速度
- auto& valueVector = value.asValueVector();
- float speed = valueVector[0].asFloat();
- float speedVar = valueVector[1].asFloat();
- static_cast<ZMLCCParticleSystem*>(pNode)->setSpeed(speed);
- static_cast<ZMLCCParticleSystem*>(pNode)->setSpeedVar(speedVar);
- }
- else if(propName == "life"){
- // 粒子生命
- auto& valueVector = value.asValueVector();
- float speed = valueVector[0].asFloat();
- float speedVar = valueVector[1].asFloat();
- static_cast<ZMLCCParticleSystem*>(pNode)->setLife(speed);
- static_cast<ZMLCCParticleSystem*>(pNode)->setLifeVar(speedVar);
- }
- else if(propName == "startSize"){
- // 初始尺寸
- auto& valueVector = value.asValueVector();
- float speed = valueVector[0].asFloat();
- float speedVar = valueVector[1].asFloat();
- static_cast<ZMLCCParticleSystem*>(pNode)->setStartSize(speed);
- static_cast<ZMLCCParticleSystem*>(pNode)->setStartSizeVar(speedVar);
- }
- else if(propName == "endSize"){
- // 结束尺寸
- auto& valueVector = value.asValueVector();
- float speed = valueVector[0].asFloat();
- float speedVar = valueVector[1].asFloat();
- static_cast<ZMLCCParticleSystem*>(pNode)->setEndSize(speed);
- static_cast<ZMLCCParticleSystem*>(pNode)->setEndSizeVar(speedVar);
- }
- else if(propName == "startSpin"){
- // 开始旋转角度:
- auto& valueVector = value.asValueVector();
- float speed = valueVector[0].asFloat();
- float speedVar = valueVector[1].asFloat();
- static_cast<ZMLCCParticleSystem*>(pNode)->setStartSpin(speed);
- static_cast<ZMLCCParticleSystem*>(pNode)->setStartSpinVar(speedVar);
- }
- else if(propName == "endSpin"){
- // 结束旋转角度
- auto& valueVector = value.asValueVector();
- float speed = valueVector[0].asFloat();
- float speedVar = valueVector[1].asFloat();
- static_cast<ZMLCCParticleSystem*>(pNode)->setEndSpin(speed);
- static_cast<ZMLCCParticleSystem*>(pNode)->setEndSpinVar(speedVar);
- }
- else if(propName == "angle"){
- // 发射角度
- auto& valueVector = value.asValueVector();
- float speed = valueVector[0].asFloat();
- float speedVar = valueVector[1].asFloat();
- static_cast<ZMLCCParticleSystem*>(pNode)->setAngle(speed);
- static_cast<ZMLCCParticleSystem*>(pNode)->setAngleVar(speedVar);
- }
- else if(propName == "tangentialAccel"){
- // 切向加速度
- auto& valueVector = value.asValueVector();
- float speed = valueVector[0].asFloat();
- float speedVar = valueVector[1].asFloat();
- static_cast<ZMLCCParticleSystem*>(pNode)->setTangentialAccel(speed);
- static_cast<ZMLCCParticleSystem*>(pNode)->setTangentialAccelVar(speedVar);
- }
- else if(propName == "radialAccel"){
- // 径向加速度:
- auto& valueVector = value.asValueVector();
- float speed = valueVector[0].asFloat();
- float speedVar = valueVector[1].asFloat();
- static_cast<ZMLCCParticleSystem*>(pNode)->setRadialAccel(speed);
- static_cast<ZMLCCParticleSystem*>(pNode)->setRadialAccelVar(speedVar);
- }
- else if(propName == "startRadius"){
- // 开始半径:
- auto& valueVector = value.asValueVector();
- float speed = valueVector[0].asFloat();
- float speedVar = valueVector[1].asFloat();
- static_cast<ZMLCCParticleSystem*>(pNode)->setStartSpin(speed);
- static_cast<ZMLCCParticleSystem*>(pNode)->setStartSpinVar(speedVar);
- }
- else if(propName == "endRadius"){
- // 结束半径
- auto& valueVector = value.asValueVector();
- float speed = valueVector[0].asFloat();
- float speedVar = valueVector[1].asFloat();
- static_cast<ZMLCCParticleSystem*>(pNode)->setEndRadius(speed);
- static_cast<ZMLCCParticleSystem*>(pNode)->setEndRadiusVar(speedVar);
- }
- else if(propName == "rotatePerSecond"){
- // 旋转:
- auto& valueVector = value.asValueVector();
- float speed = valueVector[0].asFloat();
- float speedVar = valueVector[1].asFloat();
- static_cast<ZMLCCParticleSystem*>(pNode)->setRotatePerSecond(speed);
- static_cast<ZMLCCParticleSystem*>(pNode)->setRotatePerSecondVar(speedVar);
- }
- else if (propName == "enabled")
- {
- bool enabled = value.asBool();
- static_cast<Control*>(pNode)->setEnabled(enabled);
- }
- else if(propName == "string"){
- auto value = getBaseValue(pNode, propName);
- static_cast<Label*>(pNode)->setString(value.asString());
- }
- else if (propName == "useMaterial") {
- auto isUseMaterial = value.asBool();
- static_cast<Sprite*>(pNode)->setMaterialEnable(isUseMaterial);
- }
- else if (propName == "bakeAnimation") {
- RedBakeNodeFrame frame;
- frame.animationName = value.asValueVector()[0].asString();
- frame.elapsedTime = 0;
- frame.loop = value.asValueVector()[2].asBool();
- RedBakeNode *bakeNode = dynamic_cast<RedBakeNode*>(pNode);
- bakeNode->setBakeFrame(frame);
- }
- else
- {
- log("unsupported property name is %s", propName.c_str());
- CCASSERT(false, "unsupported property now");
- }
- }
- }
- }
- void REDAnimationManager::setFirstFrame(Node *pNode, REDSequenceProperty *pSeqProp, float fTweenDuration)
- {
- auto& keyframes = pSeqProp->getKeyframes();
-
- if (keyframes.empty())
- {
- // Use base value (no animation)
- auto& baseValue = getBaseValue(pNode, pSeqProp->getName());
- auto obj = getObject(pNode, pSeqProp->getName());
- CCASSERT(!baseValue.isNull(), "No baseValue found for property");
- setAnimatedProperty(pSeqProp->getName(), pNode, baseValue, obj, fTweenDuration, false);
- }
- else
- {
- // Use first keyframe
- REDKeyframe *keyframe = keyframes.at(0);
- setAnimatedProperty(pSeqProp->getName(), pNode, keyframe->getValue(), keyframe->getObject(), fTweenDuration, false);
- }
- }
- ActionInterval* REDAnimationManager::getEaseAction(ActionInterval *pAction, REDKeyframe::EasingType easingType, float* fEasingOpt)
- {
- if (dynamic_cast<Sequence*>(pAction))
- {
- return pAction;
- }
-
- if (easingType == REDKeyframe::EasingType::LINEAR)
- {
- return pAction;
- }
- else if (easingType == REDKeyframe::EasingType::INSTANT)
- {
- return REDEaseInstant::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::CUBIC_IN)
- {
- return EaseIn::create(pAction, *fEasingOpt);
- }
- else if (easingType == REDKeyframe::EasingType::CUBIC_OUT)
- {
- return EaseOut::create(pAction, *fEasingOpt);
- }
- else if (easingType == REDKeyframe::EasingType::CUBIC_INOUT)
- {
- return EaseInOut::create(pAction, *fEasingOpt);
- }
- else if (easingType == REDKeyframe::EasingType::BACK_IN)
- {
- return EaseBackIn::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::BACK_OUT)
- {
- return EaseBackOut::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::BACK_INOUT)
- {
- return EaseBackInOut::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::BOUNCE_IN)
- {
- return EaseBounceIn::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::BOUNCE_OUT)
- {
- return EaseBounceOut::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::BOUNCE_INOUT)
- {
- return EaseBounceInOut::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::ELASTIC_IN)
- {
- return EaseElasticIn::create(pAction, *fEasingOpt);
- }
- else if (easingType == REDKeyframe::EasingType::ELASTIC_OUT)
- {
- return EaseElasticOut::create(pAction, *fEasingOpt);
- }
- else if (easingType == REDKeyframe::EasingType::ELASTIC_INOUT)
- {
- return EaseElasticInOut::create(pAction, *fEasingOpt);
- }
- //add new
- else if (easingType == REDKeyframe::EasingType::SineIn)
- {
- return EaseSineIn::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::SineOut)
- {
- return EaseSineOut::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::SineInOut)
- {
- return EaseSineInOut::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::ExponentialIn)
- {
- return EaseExponentialIn::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::ExponentialOut)
- {
- return EaseExponentialOut::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::ExponentialInOut)
- {
- return EaseExponentialInOut::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::CircleActionIn)
- {
- return EaseCircleActionIn::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::CircleActionOut)
- {
- return EaseCircleActionOut::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::CircleActionInOut)
- {
- return EaseCircleActionInOut::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::QuadraticActionIn)
- {
- return EaseQuadraticActionIn::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::QuadraticActionOut)
- {
- return EaseQuadraticActionOut::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::QuadraticActionInOut)
- {
- return EaseQuadraticActionInOut::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::CubicActionIn)
- {
- return EaseCubicActionIn::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::CubicActionOut)
- {
- return EaseCubicActionOut::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::CubicActionInOut)
- {
- return EaseCubicActionInOut::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::QuarticActionIn)
- {
- return EaseQuarticActionIn::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::QuarticActionOut)
- {
- return EaseQuarticActionOut::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::QuarticActionInOut)
- {
- return EaseQuarticActionInOut::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::QuinticActionIn)
- {
- return EaseQuinticActionIn::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::QuinticActionOut)
- {
- return EaseQuinticActionOut::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::QuinticActionInOut)
- {
- return EaseQuinticActionInOut::create(pAction);
- }
- else if (easingType == REDKeyframe::EasingType::Custom)
- {
- auto ease = EaseBezierByTimeAction::create(pAction);
- ease->setBezierParamer(fEasingOpt[0], fEasingOpt[1], fEasingOpt[2], fEasingOpt[3]);
- return ease;
- }
- else
- {
- log("REDReader: Unknown easing type %d", static_cast<int>(easingType));
- return pAction;
- }
- }
- Sequence* REDAnimationManager::actionForCallbackChannel(REDSequenceProperty* channel) {
-
- float lastKeyframeTime = 0;
-
- Vector<FiniteTimeAction*> actions;
- auto& keyframes = channel->getKeyframes();
- ssize_t numKeyframes = keyframes.size();
- for (long i = 0; i < numKeyframes; ++i)
- {
- REDKeyframe *keyframe = keyframes.at(i);
- float timeSinceLastKeyframe = keyframe->getTime() - lastKeyframeTime;
- lastKeyframeTime = keyframe->getTime();
- if(timeSinceLastKeyframe > 0) {
- actions.pushBack(DelayTime::create(timeSinceLastKeyframe));
- }
-
- auto& keyVal = keyframe->getValue().asValueVector();
- std::string selectorName = keyVal[0].asString();
- REDReader::TargetType selectorTarget = (REDReader::TargetType)keyVal[1].asInt();
-
-
- Ref* target = nullptr;
-
- if(selectorTarget == REDReader::TargetType::DOCUMENT_ROOT)
- target = _rootNode;
- else if (selectorTarget == REDReader::TargetType::OWNER)
- target = _owner;
-
- if (selectorTarget == REDReader::TargetType::REDWISE_EVENT) {
- CallFunc* wiseCall = CallFunc::create([=](){
- EventCustom wiseEvent("REDAnimationManager_ActionForCallbackChannel_RedWiseEvent");
- string name = selectorName;
- wiseEvent.setUserData(&name);
- Director::getInstance()->getEventDispatcher()->dispatchEvent(&wiseEvent);
- });
- actions.pushBack(wiseCall);
- continue;
- }
-
- if(target != nullptr)
- {
- if(!selectorName.empty())
- {
- SEL_CallFuncN selCallFunc = 0;
-
- REDSelectorResolver* targetAsREDSelectorResolver = dynamic_cast<REDSelectorResolver *>(target);
-
- if(targetAsREDSelectorResolver != nullptr)
- {
- selCallFunc = targetAsREDSelectorResolver->onResolveREDCCCallFuncSelector(target, selectorName.c_str ());
- }
-
- if(selCallFunc == 0)
- {
- CCLOG("Skipping selector '%s' since no REDSelectorResolver is present.", selectorName.c_str());
- }
- else
- {
- auto savedTarget = std::make_shared<Vector<Ref*>>();
- savedTarget->pushBack(target);
-
- ///bug : 若actions不析构,将会导致target无法释放,出现内存泄漏
- auto callback = CallFuncN::create([savedTarget, selectorName,selCallFunc](Node* sender){
- Director::getInstance()->getEventDispatcher()->dispatchCustomEvent("__CCCallFuncSelector__"+selectorName);
- auto t = savedTarget->at(0);
- (t->*selCallFunc)(sender);
- });
-
- actions.pushBack(callback);
- }
- }
- else
- {
- CCLOG("Unexpected empty selector.");
- }
- }
-
- }
- if(actions.size() < 1) return nullptr;
-
- return Sequence::create(actions);
- }
- Sequence* REDAnimationManager::actionForSoundChannel(REDSequenceProperty* channel) {
-
- float lastKeyframeTime = 0;
-
- Vector<FiniteTimeAction*> actions;
- auto& keyframes = channel->getKeyframes();
- ssize_t numKeyframes = keyframes.size();
- for (int i = 0; i < numKeyframes; ++i)
- {
- REDKeyframe *keyframe = keyframes.at(i);
- float timeSinceLastKeyframe = keyframe->getTime() - lastKeyframeTime;
- lastKeyframeTime = keyframe->getTime();
- if(timeSinceLastKeyframe > 0) {
- actions.pushBack(DelayTime::create(timeSinceLastKeyframe));
- }
-
- stringstream ss (stringstream::in | stringstream::out);
- auto& keyVal = keyframe->getValue().asValueVector();
- std::string soundFile = keyVal[0].asString();
-
- float pitch = 0.0f, pan = 0.0f, gain = 0.0f;
- ss << keyVal[1].asString();
- ss >> pitch;
- ss.flush();
-
- ss << keyVal[2].asString();
- ss >> pan;
- ss.flush();
-
- ss << keyVal[3].asString();
- ss >> gain;
- ss.flush();
-
- actions.pushBack(REDSoundEffect::actionWithSoundFile(soundFile, pitch, pan, gain));
- }
- if(actions.size() < 1) return nullptr;
-
- return Sequence::create(actions);
- }
- Sequence* REDAnimationManager::actionForWiseChannel(REDSequenceProperty* channel) {
- float lastKeyframeTime = 0;
- Vector<FiniteTimeAction*> actions;
- auto& keyframes = channel->getKeyframes();
- ssize_t numKeyframes = keyframes.size();
- for (int i = 0; i < numKeyframes; ++i) {
- REDKeyframe *keyframe = keyframes.at(i);
- float timeSinceLastKeyframe = keyframe->getTime() - lastKeyframeTime;
- lastKeyframeTime = keyframe->getTime();
- if(timeSinceLastKeyframe > 0) {
- actions.pushBack(DelayTime::create(timeSinceLastKeyframe));
- }
-
- auto& keyVal = keyframe->getValue().asValueVector();
- std::string btnFileName = keyVal.at(0).asString();
- std::string eventName = keyVal.at(1).asString();
- bool forcePostEvent = keyVal.at(2).asBool();
- const ValueVector& params = keyVal.at(3).asValueVector();
-
- actions.pushBack(REDWiseEffect::actionWithConfig(btnFileName, eventName, forcePostEvent, params));
- }
- if(actions.size() < 1) return nullptr;
-
- return Sequence::create(actions);
- }
- void REDAnimationManager::runAction(Node *pNode, REDSequenceProperty *pSeqProp, float fTweenDuration)
- {
- auto& keyframes = pSeqProp->getKeyframes();
- ssize_t numKeyframes = keyframes.size();
-
- const char* propType = pSeqProp->getName();
- if (numKeyframes > 1)
- {
- // Make an animation!
- Vector<FiniteTimeAction*> actions;
-
- REDKeyframe *keyframeFirst = keyframes.at(0);
- float timeFirst = keyframeFirst->getTime() + fTweenDuration;
-
- if (timeFirst > 0)
- {
- actions.pushBack(DelayTime::create(timeFirst));
- }
-
- for (ssize_t i = 0; i < numKeyframes - 1; ++i)
- {
- REDKeyframe *kf0 = keyframes.at(i);
- REDKeyframe *kf1 = keyframes.at(i+1);
-
- if(i == 0 && (strcmp(propType, "animation") == 0 || strcmp(propType, "frame") == 0 || strcmp(propType, "string") == 0 || strcmp(propType, "bakeAnimation") == 0)){
- //第一个关键帧,子red文件和spine动画需要处理一下
- ActionInterval *action = getAction(kf0, kf0, pSeqProp->getName(), pNode);
- actions.pushBack(action);
- }
-
- ActionInterval *action = getAction(kf0, kf1, pSeqProp->getName(), pNode);
- if (action)
- {
- // Apply easing
- action = getEaseAction(action, kf0->getEasingType(), kf0->getEasingOpt());
-
- actions.pushBack(action);
- }
- }
-
- //add song
- auto seq = Sequence::create(actions);
- auto speed = Speed::create(seq, _speed);
- speed->setTag(101);
- pNode->runAction(speed);
- }
- else if (numKeyframes == 1 && (strcmp(propType, "animation") == 0 || strcmp(propType, "frame") == 0 || strcmp(propType, "bakeAnimation")))
- {
- // Make an animation!
- Vector<FiniteTimeAction*> actions;
-
- REDKeyframe *keyframeFirst = keyframes.at(0);
- float timeFirst = keyframeFirst->getTime() + fTweenDuration;
-
- if (timeFirst > 0)
- {
- actions.pushBack(DelayTime::create(timeFirst));
- }
- ActionInterval *action = getAction(keyframeFirst, keyframeFirst, pSeqProp->getName(), pNode);
- actions.pushBack(action);
- //add song
- auto seq = Sequence::create(actions);
- auto speed = Speed::create(seq, _speed);
- speed->setTag(101);
- pNode->runAction(speed);
- }
- }
- void REDAnimationManager::updateSpeed(float speed, Node* node) {
- std::vector<Action*> actions;
- _rootNode->getActionManager()->getActionsByTag(101, node, actions);
- std::vector<Action*>::iterator iter = actions.begin();
- while (iter != actions.end()) {
- Speed* sp = dynamic_cast<Speed*>(*iter);
- if (sp != nullptr) {
- sp->setSpeed(_speed);
- }
- iter ++;
- }
- Vector<Node*> children = node->getChildren();
- Vector<Node*>::iterator iter2 = children.begin();
- while (iter2 != children.end()) {
- updateSpeed(speed, *iter2);
- iter2 ++;
- }
- }
- void REDAnimationManager::updateSpeed(float speed) {
- _speed = speed;
- updateSpeed(speed, _rootNode);
- }
- void REDAnimationManager::runAnimations(const char *pName, float fTweenDuration)
- {
- runAnimationsForSequenceNamedTweenDuration(pName, fTweenDuration);
- }
- void REDAnimationManager::runAnimations(const char *pName)
- {
- runAnimationsForSequenceNamed(pName);
- }
- void REDAnimationManager::runAnimationsWithTag(int nSeqId, int tag){
- _lastTag = _nowTag;
- _nowTag = tag;
- runAnimationsForSequenceIdTweenDuration(nSeqId, 0);
- }
- void REDAnimationManager::runAnimationsWithListen(int nSeqId, REDAnimationManagerDelegate* listen){
- runAnimationsForSequenceIdTweenDuration(nSeqId, 0, nullptr, listen);
- }
-
- void REDAnimationManager::runAnimations(int nSeqId, float fTweenDuraiton)
- {
- runAnimationsForSequenceIdTweenDuration(nSeqId, fTweenDuraiton);
- }
- void REDAnimationManager::refreshStatusOnFirstFream(int nSeqId, float fTweenDuration){
- REDSequence* lastSeq = _runningSequence.first;
- auto lastCallback = _runningSequence.second;
- _runningSequence.first = nullptr;
- _runningSequence.second = nullptr;
- stopRootNodeAction(lastSeq, lastCallback);
-
- resetAllChildrenAnimtion(nSeqId, fTweenDuration, false);
- }
- void REDAnimationManager::runAnimationsForSequenceIdTweenDuration(int nSeqId, float fTweenDuration, const std::function<void(cocos2d::Node*, AnimationCompleteType)> &callback, REDAnimationManagerDelegate* listen)
- {
- REDSequence *seq = getSequence(nSeqId);
- CCASSERT(seq, "Sequence id couldn't be found");
-
- REDSequence* lastSeq = _runningSequence.first;
- auto lastCallback = _runningSequence.second;
- _runningSequence.first = seq;
- _runningSequence.second = callback;
-
- stopRootNodeAction(lastSeq, lastCallback);
- resetAllChildrenAnimtion(nSeqId, fTweenDuration, true);
-
- _listen = listen;
-
- // Set the running scene
- if(seq->getCallbackChannel() != nullptr) {
- Action* action = (Action *)actionForCallbackChannel(seq->getCallbackChannel());
- if(action != nullptr) {
- action->setTag(animationTag);
- _rootNode->runAction(action);
- _runningActions[_rootNode].pushBack(action);
- }
- }
- if(seq->getSoundChannel() != nullptr) {
- Action* action = (Action *)actionForSoundChannel(seq->getSoundChannel());
- if(action != nullptr) {
- action->setTag(animationTag);
- _rootNode->runAction(action);
- _runningActions[_rootNode].pushBack(action);
- }
- }
-
- if (seq->getWiseChannel() != nullptr) {
- Action* action = (Action *)actionForWiseChannel(seq->getWiseChannel());
- if (action != nullptr) {
- action->setTag(animationTag);
- _rootNode->runAction(action);
- _runningActions[_rootNode].pushBack(action);
- }
- }
-
- // Make callback at end of sequence
- Action *completeAction = Sequence::createWithTwoActions(DelayTime::create(seq->getDuration() + fTweenDuration),
- CallFunc::create(std::bind(&REDAnimationManager::sequenceCompleted, this, callback)));
- completeAction->setTag(animationTag);
- _rootNode->runAction(completeAction);
- _runningActions[_rootNode].pushBack(completeAction);
- }
- //add by djd
- Spawn* REDAnimationManager::getNodeAniByName(const char *pName, Node* pNode,Vec2 orginPos){
- Spawn *tAction = nullptr;
- int nSeqId = getSequenceId(pName);
- for (auto nodeSeqIter = _nodeSequences.begin(); nodeSeqIter != _nodeSequences.end(); ++nodeSeqIter)
- {
- Node *node = nodeSeqIter->first;
- if (node != pNode) {
- continue;
- }
- // Refer to REDReader::readKeyframe() for the real type of value
- auto seqs = nodeSeqIter->second;
- auto seqNodeProps = seqs[nSeqId];
- if (!seqNodeProps.empty())
- {
- // Reset nodes that have sequence node properties, and run actions on them
- Vector<FiniteTimeAction*> seqList;
- for (auto iter = seqNodeProps.begin(); iter != seqNodeProps.end(); ++iter)
- {
- const std::string propName = iter->first;
- REDSequenceProperty *pSeqProp = iter->second;
- auto& keyframes = pSeqProp->getKeyframes();
- ssize_t numKeyframes = keyframes.size();
-
- if (numKeyframes > 1)
- {
- // Make an animation!
- Vector<FiniteTimeAction*> actions;
-
- REDKeyframe *keyframeFirst = keyframes.at(0);
- float timeFirst = keyframeFirst->getTime();
-
- if (timeFirst > 0)
- {
- actions.pushBack(DelayTime::create(timeFirst));
- }
-
- for (ssize_t i = 0; i < numKeyframes - 1; ++i)
- {
- REDKeyframe *kf0 = keyframes.at(i);
- REDKeyframe *kf1 = keyframes.at(i+1);
-
- ActionInterval *action = nullptr;
- //重写position
-
- if (strcmp(pSeqProp->getName(), "position") == 0)
- {
- float duration = kf1->getTime() - (kf0 ? kf0->getTime() : 0);
- // Get position type
- auto& array = getBaseValue(pNode, propName).asValueVector();
- REDReader::PositionType type = (REDReader::PositionType)array[2].asInt();
-
- // Get relative position
- auto value = kf1->getValue().asValueVector();
- float x = value[0].asFloat();
- float y = value[1].asFloat();
-
- Size containerSize = getContainerSize(pNode->getParent());
-
- Vec2 absPos = getAbsolutePosition(Vec2(x,y), type, containerSize, propName);
-
- action = MoveTo::create(duration, Vec2(absPos.x + orginPos.x, absPos.y + orginPos.y));
- }else{
- action = getAction(kf0, kf1, pSeqProp->getName(), pNode);
- }
-
- if (action)
- {
- // Apply easing
- action = getEaseAction(action, kf0->getEasingType(), kf0->getEasingOpt());
-
- actions.pushBack(action);
- }
- }
-
- auto seq = Sequence::create(actions);
- seqList.pushBack(seq);
- }
- }
- tAction = Spawn::create(seqList);
- }
- break;
- }
- return tAction;
- }
- void REDAnimationManager::runAnimationsForSequenceNamedTweenDuration(const char *pName, float fTweenDuration, const std::function<void(cocos2d::Node*, AnimationCompleteType)> &callback)
- {
- int seqId = getSequenceId(pName);
- if (seqId != -1) {
- runAnimationsForSequenceIdTweenDuration(seqId, fTweenDuration, callback);
- }else{
- CCASSERT(false, "Sequence id couldn't be found");
- }
- }
- void REDAnimationManager::runAnimationsForSequenceNamed(const char *pName)
- {
- runAnimationsForSequenceNamedTweenDuration(pName, 0);
- }
- void REDAnimationManager::debug()
- {
-
- }
- void REDAnimationManager::setAnimationCompletedCallback(Ref *target, SEL_CallFunc callbackFunc) {
- if (target)
- {
- target->retain();
- }
-
- if (_target)
- {
- _target->release();
- }
-
- _target = target;
- _animationCompleteCallbackFunc = callbackFunc;
- }
- void REDAnimationManager::setCallFunc(CallFunc* callFunc, const std::string &callbackNamed)
- {
- _keyframeCallFuncs.insert(callbackNamed, callFunc);
- }
- void REDAnimationManager::sequenceCompleted(const std::function<void(cocos2d::Node*, AnimationCompleteType)> &callback)
- {
- REDSequence* sequence = _runningSequence.first;
- const char *runningSequenceName = sequence->getName();
- int seqId = sequence->getSequenceId();
- int nextSeqId = sequence->getChainedSequenceId();
- _runningSequence.first = nullptr;
- _runningSequence.second = nullptr;
-
- if(_lastCompletedSequenceName != runningSequenceName) {
- _lastCompletedSequenceName = runningSequenceName;
- }
-
- if (nextSeqId != -1)
- {
- if(callback) {
- callback(_rootNode, AnimationCompleteType::CHAINED);
- }
-
- REDAnimationManagerDelegate* animationManagerDelegate = dynamic_cast<REDAnimationManagerDelegate*>(_rootNode);
- if (animationManagerDelegate) { // 方式1 新加的 用强转触发
- //播完时间线,自动播放下一条
- animationManagerDelegate->completedAnimationAndPlayNextSequenceNamed(runningSequenceName, seqId, _nowTag);
- animationManagerDelegate->completedAnimationSequenceNamed(runningSequenceName, seqId, _nowTag);
- } else if (_delegate) { // 方式2 原有的 用代理触发
- //播完时间线,自动播放下一条
- _delegate->completedAnimationAndPlayNextSequenceNamed(runningSequenceName, seqId, _nowTag);
- _delegate->completedAnimationSequenceNamed(runningSequenceName, seqId, _nowTag);
- }
-
- if(_listen){
- //播完时间线,自动播放下一条
- auto listen = _listen;
- _listen = nullptr;
- listen->completedAnimationAndPlayNextSequenceNamed(runningSequenceName, seqId, _nowTag);
- listen->completedAnimationSequenceNamed(runningSequenceName, seqId, _nowTag);
- }
-
- runAnimationsForSequenceIdTweenDuration(nextSeqId, 0, callback);
- }
- else
- {
- if(callback){
- callback(_rootNode, AnimationCompleteType::COMPLETED);
- }
- REDAnimationManagerDelegate* animationManagerDelegate = dynamic_cast<REDAnimationManagerDelegate*>(_rootNode);
- if (animationManagerDelegate) { // 方式1 新加的 用强转触发
- animationManagerDelegate->completedAnimationSequenceNamed(runningSequenceName, seqId, _nowTag);
- } else if (_delegate) { // 方式2 原有的
- // There may be another runAnimation() call in this delegate method
- // which will assign _runningSequence
- _delegate->completedAnimationSequenceNamed(runningSequenceName, seqId, _nowTag);
- }
-
- if(_listen){
- auto listen = _listen;
- _listen = nullptr;
- listen->completedAnimationSequenceNamed(runningSequenceName, seqId, _nowTag);
- }
- }
- }
- void REDAnimationManager::stopAllNodeAction(){
- _lastTag = _nowTag;
- REDSequence* lastSeq = _runningSequence.first;
- auto lastCallback = _runningSequence.second;
- _runningSequence.first = nullptr;
- _runningSequence.second = nullptr;
-
- stopRootNodeAction(lastSeq, lastCallback);
- for (auto nodeSeqIter = _nodeSequences.begin(); nodeSeqIter != _nodeSequences.end(); ++nodeSeqIter)
- {
- Node *node = nodeSeqIter->first;
- node->stopAllActions();
- }
- }
- //MARK: - 私有封装
- void REDAnimationManager::stopRootNodeAction(REDSequence* sequence, std::function<void(cocos2d::Node*, AnimationCompleteType)> callback){
- // REDSequence* sequence = _runningSequence.first;
- if(sequence)
- {
- // if(_runningSequence.second){
- // _runningSequence.second(_rootNode, AnimationCompleteType::STOPED);
- // }
- if(callback){
- callback(_rootNode, AnimationCompleteType::STOPED);
- }
- const char *runningSequenceName = sequence->getName();
- int seqId = sequence->getSequenceId();
-
- REDAnimationManagerDelegate* animationManagerDelegate = dynamic_cast<REDAnimationManagerDelegate*>(_rootNode);
- if (animationManagerDelegate) { // 方式1 新加的 用强转触发
- animationManagerDelegate->stopAnimationSequenceNamed(runningSequenceName, seqId, _lastTag);
- } else if (_delegate) { // 方式2 原有的 用代理触发
- _delegate->stopAnimationSequenceNamed(runningSequenceName, seqId, _lastTag);
- }
- if(_listen){
- auto listen = _listen;
- _listen = nullptr;
- listen->stopAnimationSequenceNamed(runningSequenceName, seqId, _lastTag);
- }
- }
-
- // _runningSequence.first = nullptr;
- // _runningSequence.second = nullptr;
-
- for(const auto &pair:_runningActions)
- {
- for(const auto action:pair.second)
- pair.first->stopAction(action);
- }
- _runningActions.clear();
- }
- void REDAnimationManager::resetAllChildrenAnimtion(int nSeqId, float fTweenDuration, bool isRunAction){
- for (auto nodeSeqIter = _nodeSequences.begin(); nodeSeqIter != _nodeSequences.end(); ++nodeSeqIter)
- {
- Node *node = nodeSeqIter->first;
- node->stopAllActions();
-
- // Refer to REDReader::readKeyframe() for the real type of value
- auto seqs = nodeSeqIter->second;
- auto seqNodeProps = seqs[nSeqId];
-
- std::set<std::string> seqNodePropNames;
-
- if (!seqNodeProps.empty())
- {
- // Reset nodes that have sequence node properties, and run actions on them
- for (auto iter = seqNodeProps.begin(); iter != seqNodeProps.end(); ++iter)
- {
- const std::string propName = iter->first;
- REDSequenceProperty *seqProp = iter->second;
- seqNodePropNames.insert(propName);
- setFirstFrame(node, seqProp, fTweenDuration);
- if(isRunAction){
- runAction(node, seqProp, fTweenDuration);
- }
- }
- }
-
- // Reset the nodes that may have been changed by other timelines
- auto& nodeBaseValues = _baseValues[node];
-
- if (!nodeBaseValues.empty())
- {
- for (auto iter = nodeBaseValues.begin(); iter != nodeBaseValues.end(); ++iter)
- {
- if (seqNodePropNames.find(iter->first) == seqNodePropNames.end())
- {
- setAnimatedProperty(iter->first, node, iter->second, nullptr, fTweenDuration,true);
- }
- }
- }
-
- auto& nodeObject = _objects[node];
-
- if (!nodeObject.empty())
- {
- for (auto iter = nodeObject.begin(); iter != nodeObject.end(); ++iter)
- {
- if (seqNodePropNames.find(iter->first) == seqNodePropNames.end())
- {
- setAnimatedProperty(iter->first, node, Value(), iter->second, fTweenDuration,true);
- }
- }
- }
- }
- }
- //void REDAnimationManager::addListen(REDAnimationManagerDelegate* pDelegate){
- // _listen = pDelegate;
- //}
- //
- //void REDAnimationManager::removeListen(REDAnimationManagerDelegate* pDelegate){
- // _listen = nullptr;
- //}
- #pragma mark - Begin BatchNode
- ///add by songqingyu
- void REDAnimationManager::setREDRootPath(std::string redRootPath){
- _redRootPath = redRootPath;
- }
- void REDAnimationManager::setReaderPlist(std::unordered_set<std::string> plistSt,std::unordered_set<std::string> replacePlistSt){
- _readerPlistSt = plistSt;
- _repleacePlistSt=replacePlistSt;
- }
- void REDAnimationManager::addDisplayFrameKeykframe(REDKeyframe* kf){
- _needResetSpriteFrames.pushBack(kf);
- }
- void REDAnimationManager::addSpriteFrameForNode(cocos2d::Node* pNode,const std::string& propName,const std::string& spriteFile,const std::string& spriteSheet){
- _needResetObjProps[pNode][propName] = {spriteFile,spriteSheet};
- }
- void REDAnimationManager::resetSpriteFrameOfAllChildrenAnimtion(){
- for (REDKeyframe *kf : _needResetSpriteFrames) {
- const ValueVector& vv = kf->getValue().asValueVector();
- std::string spriteSheet = vv[0].asString();
- std::string spriteFile = vv[1].asString();
- kf->setObject(getSpriteFrameByName(spriteFile, spriteSheet));
- }
- for (auto it : _needResetObjProps) {
- for (auto pp : it.second) {
- SpriteFrame* sf = dynamic_cast<SpriteFrame*>(getObject(it.first, pp.first));
- if (sf) {
- SpriteFrame* tmp = getSpriteFrameByName(pp.second[0], pp.second[1]);
- if(sf != tmp && tmp){
- setObject(tmp, it.first, pp.first);
- }
- }
- }
- }
- }
- ///
- cocos2d::SpriteFrame* REDAnimationManager::getSpriteFrameByName(const string& spriteFile,const string& spriteSheet,bool useDefaultEmpty){
- cocos2d::SpriteFrame* spriteFrame = nullptr;
- SpriteFrameCache* frameCache = SpriteFrameCache::getInstance();
- TextureCache* textCache = Director::getInstance()->getTextureCache();
- spriteFrame = frameCache->getSpriteFrameByName(spriteFile,_readerPlistSt);
- if (spriteFrame == nullptr) {
- if (CocosConfig::getIgnoreCCBPath()) {
- string spFile = _redRootPath + spriteFile;
- Texture2D * texture = textCache->addImage(spFile.c_str());
- if(texture != NULL) {
- Rect bounds = Rect(0, 0,
- texture->getContentSize().width,
- texture->getContentSize().height);
- spriteFrame = SpriteFrame::createWithTexture(texture, bounds);
- if (spriteFrame) {
- spriteFrame->setTextureFilename(spriteFile);
- }
- }
- }
- else{
- if (spriteSheet.empty())
- {
- string spFile = _redRootPath + spriteFile;
- Texture2D * texture = textCache->addImage(spFile.c_str());
- if(texture != NULL) {
- Rect bounds = Rect(0, 0,
- texture->getContentSize().width,
- texture->getContentSize().height);
- spriteFrame = SpriteFrame::createWithTexture(texture, bounds);
- if (spriteFrame) {
- spriteFrame->setTextureFilename(spFile);
- }
- }
- }
- else
- {
- string spSheet = _redRootPath + spriteSheet;
- frameCache->addSpriteFramesWithFile(spSheet);
- spriteFrame = frameCache->getSpriteFrameByName(spriteFile,{spSheet});
- }
- }
- }
-
- //add by djd 防止崩溃,用默认空白图
- if (!spriteFrame&&useDefaultEmpty) {
- string spFile = CocosConfig::getDefaultEmptyPic();
- Texture2D * texture = textCache->addImage(spFile.c_str());
- if(texture != NULL) {
- Rect bounds = Rect(0, 0,
- texture->getContentSize().width,
- texture->getContentSize().height);
- spriteFrame = SpriteFrame::createWithTexture(texture, bounds);
- if (spriteFrame) {
- spriteFrame->setTextureFilename(spFile);
- }
- }
- }
- return spriteFrame;
- }
- ///add by songqingyu
- #pragma mark End BatchNode -
- // Custom actions
- /************************************************************
- REDSetSpriteFrame
- ************************************************************/
- REDSetSpriteFrame* REDSetSpriteFrame::create(SpriteFrame *pSpriteFrame)
- {
- REDSetSpriteFrame *ret = new (std::nothrow) REDSetSpriteFrame();
- if (ret)
- {
- if (ret->initWithSpriteFrame(pSpriteFrame))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- }
-
- return ret;
- }
- bool REDSetSpriteFrame::initWithSpriteFrame(SpriteFrame *pSpriteFrame)
- {
- _spriteFrame = pSpriteFrame;
- CC_SAFE_RETAIN(_spriteFrame);
-
- return true;
- }
- REDSetSpriteFrame::~REDSetSpriteFrame()
- {
- CC_SAFE_RELEASE_NULL(_spriteFrame);
- }
- REDSetSpriteFrame* REDSetSpriteFrame::clone() const
- {
- // no copy constructor
- auto a = new (std::nothrow) REDSetSpriteFrame();
- a->initWithSpriteFrame(_spriteFrame);
- a->autorelease();
- return a;
- }
- REDSetSpriteFrame* REDSetSpriteFrame::reverse() const
- {
- // returns a copy of itself
- return this->clone();
- }
- void REDSetSpriteFrame::update(float time)
- {
- ActionInstant::update(time);
- static_cast<Sprite*>(_target)->setSpriteFrame(_spriteFrame);
- }
- /************************************************************
- REDSoundEffect
- ************************************************************/
- REDSoundEffect* REDSoundEffect::actionWithSoundFile(const std::string &filename, float pitch, float pan, float gain) {
- REDSoundEffect* pRet = new (std::nothrow) REDSoundEffect();
- if (pRet != nullptr && pRet->initWithSoundFile(filename, pitch, pan, gain))
- {
- pRet->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(pRet);
- }
- return pRet;
- }
- /************************************************************
- REDWiseEffect
- ************************************************************/
- REDWiseEffect* REDWiseEffect::actionWithConfig(const std::string &btnFileName, const std::string &eventName, bool forcePostEvent, const ValueVector ¶ms) {
- REDWiseEffect* pRet = new (std::nothrow) REDWiseEffect();
- if (pRet != nullptr && pRet->initWithConfig(btnFileName, eventName, forcePostEvent, params)) {
- pRet->autorelease();
- } else {
- CC_SAFE_RELEASE(pRet);
- }
- return pRet;
- }
- REDWiseEffect::~REDWiseEffect() {}
- bool REDWiseEffect::initWithConfig(const std::string &btnFileName, const std::string &eventName, bool forcePostEvent, const ValueVector ¶ms) {
- _btnFileName = btnFileName;
- _eventName = eventName;
- _forcePostEvent = forcePostEvent;
- _params = params;
- return true;
- }
- REDWiseEffect* REDWiseEffect::clone() const {
- // no copy constructor
- auto a = new (std::nothrow) REDWiseEffect();
- a->initWithConfig(_btnFileName, _eventName, _forcePostEvent, _params);
- a->autorelease();
- return a;
- }
- REDWiseEffect* REDWiseEffect::reverse() const {
- // returns a copy of itself
- return this->clone();
- }
- void REDWiseEffect::update(float time) {
- ActionInstant::update(time);
- if (!CocosConfig::getCCBAudioEnable()) return;
-
- std::vector<RWRedreamParam> params;
- for (const auto & paramVector : _params) {
- const auto & vec = paramVector.asValueVector();
- std::string key = vec.at(0).asString();
- float value = vec.at(1).asFloat();
-
- RWRedreamParam param;
- param.name = key;
- param.value = value;
- param.min = 0.0f;
- param.max = 0.0f;
- params.push_back(param);
- }
-
- RedWise::getInstance()->postEventByBnk(_btnFileName, _eventName, params, _forcePostEvent);
- }
-
- /************************************************************
- REDAnimation
- ************************************************************/
- REDAnimation* REDAnimation::create(int animationId)
- {
- REDAnimation *ret = new (std::nothrow) REDAnimation();
- if (ret)
- {
- if (ret->initWithAnimationId(animationId))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- }
-
- return ret;
- }
- bool REDAnimation::initWithAnimationId(int animationId)
- {
- _animationId = animationId;
-
- return true;
- }
- REDAnimation::~REDAnimation()
- {
- }
- REDAnimation* REDAnimation::clone() const
- {
- // no copy constructor
- auto a = new (std::nothrow) REDAnimation();
- a->initWithAnimationId(_animationId);
- a->autorelease();
- return a;
- }
- REDAnimation* REDAnimation::reverse() const
- {
- // returns a copy of itself
- return this->clone();
- }
- void REDAnimation::update(float time)
- {
- REDAnimationManager *manager = REDAnimationManager::fromNode(_target);
-
- if(manager){
- if(_animationId == -2 || _animationId == -1){
- // 选择了默认或者空,去获取自动播放的时间线
- _animationId = manager->getAutoPlaySequenceId();
- }
- if(_animationId == -1){
- //没有回去到auto时间线
- manager->refreshStatusOnFirstFream(_animationId, 0.0f);
- } else {
- manager->runAnimationsForSequenceIdTweenDuration(_animationId, 0.0f);
- }
- }
-
- }
- REDSoundEffect::~REDSoundEffect()
- {
- }
- bool REDSoundEffect::initWithSoundFile(const std::string &filename, float pitch, float pan, float gain) {
- _soundFile = filename;
- _pitch = pitch;
- _pan = pan;
- _gain = gain;
- return true;
- }
- REDSoundEffect* REDSoundEffect::clone() const
- {
- // no copy constructor
- auto a = new (std::nothrow) REDSoundEffect();
- a->initWithSoundFile(_soundFile, _pitch, _pan, _gain);
- a->autorelease();
- return a;
- }
- REDSoundEffect* REDSoundEffect::reverse() const
- {
- // returns a copy of itself
- return this->clone();
- }
- void REDSoundEffect::update(float time)
- {
- ActionInstant::update(time);
- if (!CocosConfig::getCCBAudioEnable()) return;
- // AudioEngine::play2d(_soundFile);
- ///强制改为播放wwise
- const std::string& eventName = _soundFile.substr(0, _soundFile.rfind("."));
- RedWise::getInstance()->postEvent(eventName);
- }
- /************************************************************
- REDLabelString
- ************************************************************/
- REDLabelString* REDLabelString::actionWithText(const std::string &text) {
- REDLabelString* pRet = new (std::nothrow) REDLabelString();
- if (pRet != nullptr && pRet->initWithText(text))
- {
- pRet->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(pRet);
- }
- return pRet;
- }
- REDLabelString::~REDLabelString()
- {
- }
- bool REDLabelString::initWithText(const std::string &text) {
- _text = text;
- return true;
- }
- REDLabelString* REDLabelString::clone() const
- {
- // no copy constructor
- auto a = new (std::nothrow) REDLabelString();
- a->initWithText(_text);
- a->autorelease();
- return a;
- }
- REDLabelString* REDLabelString::reverse() const
- {
- // returns a copy of itself
- return this->clone();
- }
- void REDLabelString::update(float time)
- {
- ActionInstant::update(time);
- auto label = static_cast<Label*>(_target);
- auto model = label->getLocalizationModel();
- if(model.isLocalization)
- {
- if(model.isCustom)
- {
- auto text = LocalizationMgr::getInstance()->getString(_text, model.customFilePath);
- static_cast<Label*>(_target)->setString(text);
- }
- else
- {
- auto text = LocalizationMgr::getInstance()->getString(_text, LOCALIZATION_DEFAULT_FILE);
- static_cast<Label*>(_target)->setString(text);
- }
- }
- else
- {
- static_cast<Label*>(_target)->setString(_text);
- }
- }
- /************************************************************
- REDRotateTo
- ************************************************************/
- REDRotateTo* REDRotateTo::create(float fDuration, float fAngle)
- {
- REDRotateTo *ret = new (std::nothrow) REDRotateTo();
- if (ret)
- {
- if (ret->initWithDuration(fDuration, fAngle))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- }
-
- return ret;
- }
- bool REDRotateTo::initWithDuration(float fDuration, float fAngle)
- {
- if (ActionInterval::initWithDuration(fDuration))
- {
- _dstAngle = fAngle;
-
- return true;
- }
- else
- {
- return false;
- }
- }
- REDRotateTo* REDRotateTo::clone() const
- {
- // no copy constructor
- auto a = new (std::nothrow) REDRotateTo();
- a->initWithDuration(_duration, _dstAngle);
- a->autorelease();
- return a;
- }
- REDRotateTo* REDRotateTo::reverse() const
- {
- CCASSERT(false, "reverse() is not supported in REDRotateTo");
- return nullptr;
- }
- void REDRotateTo::startWithTarget(Node *pNode)
- {
- ActionInterval::startWithTarget(pNode);
- _startAngle = _target->getRotation();
- _diffAngle = _dstAngle - _startAngle;
- }
- void REDRotateTo::update(float time)
- {
- _target->setRotation(_startAngle + (_diffAngle * time))
- ;
- }
- /************************************************************
- REDRotateXTO
- ************************************************************/
- REDRotateXTo* REDRotateXTo::create(float fDuration, float fAngle)
- {
- REDRotateXTo *ret = new (std::nothrow) REDRotateXTo();
- if (ret)
- {
- if (ret->initWithDuration(fDuration, fAngle))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- }
-
- return ret;
- }
- bool REDRotateXTo::initWithDuration(float fDuration, float fAngle)
- {
- if (ActionInterval::initWithDuration(fDuration))
- {
- _dstAngle = fAngle;
-
- return true;
- }
- else
- {
- return false;
- }
- }
- void REDRotateXTo::startWithTarget(Node *pNode)
- {
- //CCActionInterval::startWithTarget(pNode);
- _originalTarget = pNode;
- _target = pNode;
- _elapsed = 0.0f;
- _firstTick = true;
- _startAngle = _target->getRotationSkewX();
- _diffAngle = _dstAngle - _startAngle;
- }
- REDRotateXTo* REDRotateXTo::clone() const
- {
- // no copy constructor
- auto a = new (std::nothrow) REDRotateXTo();
- a->initWithDuration(_duration, _dstAngle);
- a->autorelease();
- return a;
- }
- REDRotateXTo* REDRotateXTo::reverse() const
- {
- CCASSERT(false, "reverse() is not supported in REDRotateXTo");
- return nullptr;
- }
- void REDRotateXTo::update(float time)
- {
- _target->setRotationSkewX(_startAngle + (_diffAngle * time));
- }
- /************************************************************
- REDRotateYTO
- ************************************************************/
- REDRotateYTo* REDRotateYTo::create(float fDuration, float fAngle)
- {
- REDRotateYTo *ret = new (std::nothrow) REDRotateYTo();
- if (ret)
- {
- if (ret->initWithDuration(fDuration, fAngle))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- }
-
- return ret;
- }
- bool REDRotateYTo::initWithDuration(float fDuration, float fAngle)
- {
- if (ActionInterval::initWithDuration(fDuration))
- {
- _dstAngle = fAngle;
-
- return true;
- }
- else
- {
- return false;
- }
- }
- REDRotateYTo* REDRotateYTo::clone() const
- {
- // no copy constructor
- auto a = new (std::nothrow) REDRotateYTo();
- a->initWithDuration(_duration, _dstAngle);
- a->autorelease();
- return a;
- }
- REDRotateYTo* REDRotateYTo::reverse() const
- {
- CCASSERT(false, "reverse() is not supported in REDRotateXTo");
- return nullptr;
- }
- void REDRotateYTo::startWithTarget(Node *pNode)
- {
- // ActionInterval::startWithTarget(pNode);
- _originalTarget = pNode;
- _target = pNode;
- _elapsed = 0.0f;
- _firstTick = true;
- _startAngle = _target->getRotationSkewY();
- _diffAngle = _dstAngle - _startAngle;
- }
- void REDRotateYTo::update(float time)
- {
- _target->setRotationSkewY(_startAngle + (_diffAngle * time));
- }
-
- /************************************************************
- REDFrameIndexTo
- ************************************************************/
- REDFrameIndexTo* REDFrameIndexTo::create(float fDuration, int startIndex, int endIndex) {
- REDFrameIndexTo *ret = new (std::nothrow) REDFrameIndexTo();
- if (ret) {
- if (ret->initWithDuration(fDuration, startIndex, endIndex)) {
- ret->autorelease();
- } else {
- CC_SAFE_DELETE(ret);
- }
- }
- return ret;
- }
-
- bool REDFrameIndexTo::initWithDuration(float fDuration, int startIndex, int endIndex) {
- if (ActionInterval::initWithDuration(fDuration)) {
- _startIndex = startIndex;
- _endIndex = endIndex;
- return true;
- } else {
- return false;
- }
- }
- REDFrameIndexTo* REDFrameIndexTo::clone() const {
- auto a = new (std::nothrow) REDFrameIndexTo();
- a->initWithDuration(_duration, _startIndex, _endIndex);
- a->autorelease();
- return a;
- }
-
- REDFrameIndexTo* REDFrameIndexTo::reverse() const {
- CCASSERT(false, "reverse() is not supported in REDFrameIndexTo");
- return nullptr;
- }
-
- void REDFrameIndexTo::startWithTarget(cocos2d::Node *pNode) {
- ActionInterval::startWithTarget(pNode);
- _diffIndex = _endIndex - _startIndex;
- }
-
- void REDFrameIndexTo::update(float time) {
- auto fasp = dynamic_cast<ZGFrameActionSprite*>(_target);
- CCASSERT(fasp != nullptr, "REDFrameIndexTo 只支持 ZGFrameActionSprite类型的图片");
- auto frameIndex = (int)(_startIndex + (_diffIndex * time));
- fasp->setFrameIndex(frameIndex);
- }
- /************************************************************
- REDParticlePosVarTo
- ************************************************************/
- REDParticlePosVarTo* REDParticlePosVarTo::create(float fDuration, cocos2d::Vec2 pos){
- REDParticlePosVarTo *ret = new (std::nothrow) REDParticlePosVarTo();
- if (ret)
- {
- if (ret->initWithDuration(fDuration, pos))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- }
-
- return ret;
- }
- bool REDParticlePosVarTo::initWithDuration(float fDuration, cocos2d::Vec2 pos){
- if (ActionInterval::initWithDuration(fDuration))
- {
- _endGravity = pos;
- return true;
- }
- else
- {
- return false;
- }
- }
- REDParticlePosVarTo* REDParticlePosVarTo::clone() const {
- // no copy constructor
- auto a = new (std::nothrow) REDParticlePosVarTo();
- a->initWithDuration(_duration, _endGravity);
- a->autorelease();
- return a;
- }
- REDParticlePosVarTo* REDParticlePosVarTo::reverse() const {
- CCASSERT(false, "reverse() is not supported in REDParticlePosVarTo");
- return nullptr;
- }
- void REDParticlePosVarTo::startWithTarget(cocos2d::Node *pNode) {
- ActionInterval::startWithTarget(pNode);
- _startGravity = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getPosVar();
- _diffGravity = _endGravity - _startGravity;
- }
- void REDParticlePosVarTo::update(float time){
- auto fasp = dynamic_cast<ZMLCCParticleSystem*>(_target);
- CCASSERT(fasp != nullptr, "REDGravityTo 只支持 ZMLCCParticleSystem");
- auto gravity = _startGravity + (_diffGravity * time);
- fasp->setPosVar(gravity);
- }
- /************************************************************
- REDGravityTo
- ************************************************************/
- REDGravityTo* REDGravityTo::create(float fDuration, cocos2d::Vec2 gravity){
- REDGravityTo *ret = new (std::nothrow) REDGravityTo();
- if (ret)
- {
- if (ret->initWithDuration(fDuration, gravity))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- }
-
- return ret;
- }
- bool REDGravityTo::initWithDuration(float fDuration, cocos2d::Vec2 gravity){
- if (ActionInterval::initWithDuration(fDuration))
- {
- _endGravity = gravity;
- return true;
- }
- else
- {
- return false;
- }
- }
- REDGravityTo* REDGravityTo::clone() const {
- // no copy constructor
- auto a = new (std::nothrow) REDGravityTo();
- a->initWithDuration(_duration, _endGravity);
- a->autorelease();
- return a;
- }
- REDGravityTo* REDGravityTo::reverse() const {
- CCASSERT(false, "reverse() is not supported in REDGravityTo");
- return nullptr;
- }
- void REDGravityTo::startWithTarget(cocos2d::Node *pNode) {
- ActionInterval::startWithTarget(pNode);
- _startGravity = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getGravity();
- _diffGravity = _endGravity - _startGravity;
- }
- void REDGravityTo::update(float time){
- auto fasp = dynamic_cast<ZMLCCParticleSystem*>(_target);
- CCASSERT(fasp != nullptr, "REDGravityTo 只支持 ZMLCCParticleSystem");
- auto gravity = _startGravity + (_diffGravity * time);
- fasp->setGravity(gravity);
- }
- /************************************************************
- REDParticleSpeedTo
- ************************************************************/
- //粒子速度
- REDParticleSpeedTo* REDParticleSpeedTo::create(float fDuration, cocos2d::Vec2 gravity){
- REDParticleSpeedTo *ret = new (std::nothrow) REDParticleSpeedTo();
- if (ret)
- {
- if (ret->initWithDuration(fDuration, gravity))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- }
-
- return ret;
- }
- bool REDParticleSpeedTo::initWithDuration(float fDuration, cocos2d::Vec2 folatVar){
- if (ActionInterval::initWithDuration(fDuration))
- {
- _endFloatVar = folatVar;
- return true;
- }
- else
- {
- return false;
- }
- }
- REDParticleSpeedTo* REDParticleSpeedTo::clone() const {
- // no copy constructor
- auto a = new (std::nothrow) REDParticleSpeedTo();
- a->initWithDuration(_duration, _endFloatVar);
- a->autorelease();
- return a;
- }
- REDParticleSpeedTo* REDParticleSpeedTo::reverse() const {
- CCASSERT(false, "reverse() is not supported in REDParticleSpeedTo");
- return nullptr;
- }
- void REDParticleSpeedTo::startWithTarget(cocos2d::Node *pNode) {
- ActionInterval::startWithTarget(pNode);
-
- float a = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getSpeed();
- float aVar = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getSpeedVar();
- _startFloatVar = Vec2(a, aVar);
- _diffFloatVar = _endFloatVar - _startFloatVar;
- }
- void REDParticleSpeedTo::update(float time){
- auto par = dynamic_cast<ZMLCCParticleSystem*>(_target);
- CCASSERT(par != nullptr, "REDParticleSpeedTo 只支持 ZMLCCParticleSystem");
- auto floatVar = _startFloatVar + (_diffFloatVar * time);
- par->setSpeed(floatVar.x);
- par->setSpeedVar(floatVar.y);
- }
- /************************************************************
- REDParticleLifeTo
- ************************************************************/
- //粒子生命
- REDParticleLifeTo* REDParticleLifeTo::create(float fDuration, cocos2d::Vec2 folatVar){
- REDParticleLifeTo *ret = new (std::nothrow) REDParticleLifeTo();
- if (ret)
- {
- if (ret->initWithDuration(fDuration, folatVar))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- }
-
- return ret;
- }
- bool REDParticleLifeTo::initWithDuration(float fDuration, cocos2d::Vec2 folatVar){
- if (ActionInterval::initWithDuration(fDuration))
- {
- _endFloatVar = folatVar;
- return true;
- }
- else
- {
- return false;
- }
- }
- REDParticleLifeTo* REDParticleLifeTo::clone() const {
- // no copy constructor
- auto a = new (std::nothrow) REDParticleLifeTo();
- a->initWithDuration(_duration, _endFloatVar);
- a->autorelease();
- return a;
- }
- REDParticleLifeTo* REDParticleLifeTo::reverse() const {
- CCASSERT(false, "reverse() is not supported in REDParticleLifeTo");
- return nullptr;
- }
- void REDParticleLifeTo::startWithTarget(cocos2d::Node *pNode) {
- ActionInterval::startWithTarget(pNode);
-
- float a = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getLife();
- float aVar = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getLifeVar();
- _startFloatVar = Vec2(a, aVar);
- _diffFloatVar = _endFloatVar - _startFloatVar;
- }
- void REDParticleLifeTo::update(float time){
- auto par = dynamic_cast<ZMLCCParticleSystem*>(_target);
- CCASSERT(par != nullptr, "REDParticleSpeedTo 只支持 ZMLCCParticleSystem");
- auto floatVar = _startFloatVar + (_diffFloatVar * time);
- par->setLife(floatVar.x);
- par->setLifeVar(floatVar.y);
- }
- /************************************************************
- REDParticleStartSizeTo
- ************************************************************/
- //粒子初始尺寸
- REDParticleStartSizeTo* REDParticleStartSizeTo::create(float fDuration, cocos2d::Vec2 folatVar){
- REDParticleStartSizeTo *ret = new (std::nothrow) REDParticleStartSizeTo();
- if (ret)
- {
- if (ret->initWithDuration(fDuration, folatVar))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- }
-
- return ret;
- }
- bool REDParticleStartSizeTo::initWithDuration(float fDuration, cocos2d::Vec2 folatVar){
- if (ActionInterval::initWithDuration(fDuration))
- {
- _endFloatVar = folatVar;
- return true;
- }
- else
- {
- return false;
- }
- }
- REDParticleStartSizeTo* REDParticleStartSizeTo::clone() const {
- // no copy constructor
- auto a = new (std::nothrow) REDParticleStartSizeTo();
- a->initWithDuration(_duration, _endFloatVar);
- a->autorelease();
- return a;
- }
- REDParticleStartSizeTo* REDParticleStartSizeTo::reverse() const {
- CCASSERT(false, "reverse() is not supported in REDParticleStartSizeTo");
- return nullptr;
- }
- void REDParticleStartSizeTo::startWithTarget(cocos2d::Node *pNode) {
- ActionInterval::startWithTarget(pNode);
-
- float a = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getStartSize();
- float aVar = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getStartSizeVar();
- _startFloatVar = Vec2(a, aVar);
- _diffFloatVar = _endFloatVar - _startFloatVar;
- }
- void REDParticleStartSizeTo::update(float time){
- auto par = dynamic_cast<ZMLCCParticleSystem*>(_target);
- CCASSERT(par != nullptr, "REDParticleSpeedTo 只支持 ZMLCCParticleSystem");
- auto floatVar = _startFloatVar + (_diffFloatVar * time);
- par->setStartSize(floatVar.x);
- par->setStartSizeVar(floatVar.y);
- }
- /************************************************************
- REDParticleEndSizeTo
- ************************************************************/
- //粒子结束时的尺寸大小
- REDParticleEndSizeTo* REDParticleEndSizeTo::create(float fDuration, cocos2d::Vec2 folatVar){
- REDParticleEndSizeTo *ret = new (std::nothrow) REDParticleEndSizeTo();
- if (ret)
- {
- if (ret->initWithDuration(fDuration, folatVar))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- }
-
- return ret;
- }
- bool REDParticleEndSizeTo::initWithDuration(float fDuration, cocos2d::Vec2 folatVar){
- if (ActionInterval::initWithDuration(fDuration))
- {
- _endFloatVar = folatVar;
- return true;
- }
- else
- {
- return false;
- }
- }
- REDParticleEndSizeTo* REDParticleEndSizeTo::clone() const {
- // no copy constructor
- auto a = new (std::nothrow) REDParticleEndSizeTo();
- a->initWithDuration(_duration, _endFloatVar);
- a->autorelease();
- return a;
- }
- REDParticleEndSizeTo* REDParticleEndSizeTo::reverse() const {
- CCASSERT(false, "reverse() is not supported in REDParticleEndSizeTo");
- return nullptr;
- }
- void REDParticleEndSizeTo::startWithTarget(cocos2d::Node *pNode) {
- ActionInterval::startWithTarget(pNode);
-
- float a = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getEndSize();
- float aVar = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getEndSizeVar();
- _startFloatVar = Vec2(a, aVar);
- _diffFloatVar = _endFloatVar - _startFloatVar;
- }
- void REDParticleEndSizeTo::update(float time){
- auto par = dynamic_cast<ZMLCCParticleSystem*>(_target);
- CCASSERT(par != nullptr, "REDParticleSpeedTo 只支持 ZMLCCParticleSystem");
- auto floatVar = _startFloatVar + (_diffFloatVar * time);
- par->setEndSize(floatVar.x);
- par->setEndSizeVar(floatVar.y);
- }
- /************************************************************
- REDParticleStartSpinTo
- ************************************************************/
- //粒子速度
- REDParticleStartSpinTo* REDParticleStartSpinTo::create(float fDuration, cocos2d::Vec2 folatVar){
- REDParticleStartSpinTo *ret = new (std::nothrow) REDParticleStartSpinTo();
- if (ret)
- {
- if (ret->initWithDuration(fDuration, folatVar))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- }
-
- return ret;
- }
- bool REDParticleStartSpinTo::initWithDuration(float fDuration, cocos2d::Vec2 folatVar){
- if (ActionInterval::initWithDuration(fDuration))
- {
- _endFloatVar = folatVar;
- return true;
- }
- else
- {
- return false;
- }
- }
- REDParticleStartSpinTo* REDParticleStartSpinTo::clone() const {
- // no copy constructor
- auto a = new (std::nothrow) REDParticleStartSpinTo();
- a->initWithDuration(_duration, _endFloatVar);
- a->autorelease();
- return a;
- }
- REDParticleStartSpinTo* REDParticleStartSpinTo::reverse() const {
- CCASSERT(false, "reverse() is not supported in REDParticleStartSpinTo");
- return nullptr;
- }
- void REDParticleStartSpinTo::startWithTarget(cocos2d::Node *pNode) {
- ActionInterval::startWithTarget(pNode);
-
- float a = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getStartSpin();
- float aVar = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getStartSpinVar();
- _startFloatVar = Vec2(a, aVar);
- _diffFloatVar = _endFloatVar - _startFloatVar;
- }
- void REDParticleStartSpinTo::update(float time){
- auto par = dynamic_cast<ZMLCCParticleSystem*>(_target);
- CCASSERT(par != nullptr, "REDParticleSpeedTo 只支持 ZMLCCParticleSystem");
- auto floatVar = _startFloatVar + (_diffFloatVar * time);
- par->setStartSpin(floatVar.x);
- par->setStartSpinVar(floatVar.y);
- }
- /************************************************************
- REDParticleEndSpinTo
- ************************************************************/
- //粒子结束角度
- REDParticleEndSpinTo* REDParticleEndSpinTo::create(float fDuration, cocos2d::Vec2 folatVar){
- REDParticleEndSpinTo *ret = new (std::nothrow) REDParticleEndSpinTo();
- if (ret)
- {
- if (ret->initWithDuration(fDuration, folatVar))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- }
-
- return ret;
- }
- bool REDParticleEndSpinTo::initWithDuration(float fDuration, cocos2d::Vec2 folatVar){
- if (ActionInterval::initWithDuration(fDuration))
- {
- _endFloatVar = folatVar;
- return true;
- }
- else
- {
- return false;
- }
- }
- REDParticleEndSpinTo* REDParticleEndSpinTo::clone() const {
- // no copy constructor
- auto a = new (std::nothrow) REDParticleEndSpinTo();
- a->initWithDuration(_duration, _endFloatVar);
- a->autorelease();
- return a;
- }
- REDParticleEndSpinTo* REDParticleEndSpinTo::reverse() const {
- CCASSERT(false, "reverse() is not supported in REDParticleEndSpinTo");
- return nullptr;
- }
- void REDParticleEndSpinTo::startWithTarget(cocos2d::Node *pNode) {
- ActionInterval::startWithTarget(pNode);
-
- float a = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getEndSpin();
- float aVar = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getEndSpinVar();
- _startFloatVar = Vec2(a, aVar);
- _diffFloatVar = _endFloatVar - _startFloatVar;
- }
- void REDParticleEndSpinTo::update(float time){
- auto par = dynamic_cast<ZMLCCParticleSystem*>(_target);
- CCASSERT(par != nullptr, "REDParticleSpeedTo 只支持 ZMLCCParticleSystem");
- auto floatVar = _startFloatVar + (_diffFloatVar * time);
- par->setEndSpin(floatVar.x);
- par->setEndSpinVar(floatVar.y);
- }
- /************************************************************
- REDParticleAngleTo
- ************************************************************/
- //粒子发射角度
- REDParticleAngleTo* REDParticleAngleTo::create(float fDuration, cocos2d::Vec2 gravity){
- REDParticleAngleTo *ret = new (std::nothrow) REDParticleAngleTo();
- if (ret)
- {
- if (ret->initWithDuration(fDuration, gravity))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- }
-
- return ret;
- }
- bool REDParticleAngleTo::initWithDuration(float fDuration, cocos2d::Vec2 folatVar){
- if (ActionInterval::initWithDuration(fDuration))
- {
- _endFloatVar = folatVar;
- return true;
- }
- else
- {
- return false;
- }
- }
- REDParticleAngleTo* REDParticleAngleTo::clone() const {
- // no copy constructor
- auto a = new (std::nothrow) REDParticleAngleTo();
- a->initWithDuration(_duration, _endFloatVar);
- a->autorelease();
- return a;
- }
- REDParticleAngleTo* REDParticleAngleTo::reverse() const {
- CCASSERT(false, "reverse() is not supported in REDParticleAngleTo");
- return nullptr;
- }
- void REDParticleAngleTo::startWithTarget(cocos2d::Node *pNode) {
- ActionInterval::startWithTarget(pNode);
-
- float a = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getAngle();
- float aVar = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getAngleVar();
- _startFloatVar = Vec2(a, aVar);
- _diffFloatVar = _endFloatVar - _startFloatVar;
- }
- void REDParticleAngleTo::update(float time){
- auto par = dynamic_cast<ZMLCCParticleSystem*>(_target);
- CCASSERT(par != nullptr, "REDParticleSpeedTo 只支持 ZMLCCParticleSystem");
- auto floatVar = _startFloatVar + (_diffFloatVar * time);
- par->setAngle(floatVar.x);
- par->setAngleVar(floatVar.y);
- }
- /************************************************************
- REDParticleTangentialAccelTo
- ************************************************************/
- //粒子重力模式切向加速度
- REDParticleTangentialAccelTo* REDParticleTangentialAccelTo::create(float fDuration, cocos2d::Vec2 gravity){
- REDParticleTangentialAccelTo *ret = new (std::nothrow) REDParticleTangentialAccelTo();
- if (ret)
- {
- if (ret->initWithDuration(fDuration, gravity))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- }
-
- return ret;
- }
- bool REDParticleTangentialAccelTo::initWithDuration(float fDuration, cocos2d::Vec2 folatVar){
- if (ActionInterval::initWithDuration(fDuration))
- {
- _endFloatVar = folatVar;
- return true;
- }
- else
- {
- return false;
- }
- }
- REDParticleTangentialAccelTo* REDParticleTangentialAccelTo::clone() const {
- // no copy constructor
- auto a = new (std::nothrow) REDParticleTangentialAccelTo();
- a->initWithDuration(_duration, _endFloatVar);
- a->autorelease();
- return a;
- }
- REDParticleTangentialAccelTo* REDParticleTangentialAccelTo::reverse() const {
- CCASSERT(false, "reverse() is not supported in REDParticleTangentialAccelTo");
- return nullptr;
- }
- void REDParticleTangentialAccelTo::startWithTarget(cocos2d::Node *pNode) {
- ActionInterval::startWithTarget(pNode);
-
- float a = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getTangentialAccel();
- float aVar = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getTangentialAccelVar();
- _startFloatVar = Vec2(a, aVar);
- _diffFloatVar = _endFloatVar - _startFloatVar;
- }
- void REDParticleTangentialAccelTo::update(float time){
- auto par = dynamic_cast<ZMLCCParticleSystem*>(_target);
- CCASSERT(par != nullptr, "REDParticleSpeedTo 只支持 ZMLCCParticleSystem");
- auto floatVar = _startFloatVar + (_diffFloatVar * time);
- par->setTangentialAccel(floatVar.x);
- par->setTangentialAccelVar(floatVar.y);
- }
- /************************************************************
- REDParticleRadialAccelTo
- ************************************************************/
- //粒子径向加速度
- REDParticleRadialAccelTo* REDParticleRadialAccelTo::create(float fDuration, cocos2d::Vec2 gravity){
- REDParticleRadialAccelTo *ret = new (std::nothrow) REDParticleRadialAccelTo();
- if (ret)
- {
- if (ret->initWithDuration(fDuration, gravity))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- }
-
- return ret;
- }
- bool REDParticleRadialAccelTo::initWithDuration(float fDuration, cocos2d::Vec2 folatVar){
- if (ActionInterval::initWithDuration(fDuration))
- {
- _endFloatVar = folatVar;
- return true;
- }
- else
- {
- return false;
- }
- }
- REDParticleRadialAccelTo* REDParticleRadialAccelTo::clone() const {
- // no copy constructor
- auto a = new (std::nothrow) REDParticleRadialAccelTo();
- a->initWithDuration(_duration, _endFloatVar);
- a->autorelease();
- return a;
- }
- REDParticleRadialAccelTo* REDParticleRadialAccelTo::reverse() const {
- CCASSERT(false, "reverse() is not supported in REDParticleRadialAccelTo");
- return nullptr;
- }
- void REDParticleRadialAccelTo::startWithTarget(cocos2d::Node *pNode) {
- ActionInterval::startWithTarget(pNode);
-
- float a = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getRadialAccel();
- float aVar = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getRadialAccelVar();
- _startFloatVar = Vec2(a, aVar);
- _diffFloatVar = _endFloatVar - _startFloatVar;
- }
- void REDParticleRadialAccelTo::update(float time){
- auto par = dynamic_cast<ZMLCCParticleSystem*>(_target);
- CCASSERT(par != nullptr, "REDParticleSpeedTo 只支持 ZMLCCParticleSystem");
- auto floatVar = _startFloatVar + (_diffFloatVar * time);
- par->setRadialAccel(floatVar.x);
- par->setRadialAccelVar(floatVar.y);
- }
- /************************************************************
- REDParticleStartRadiusTo
- ************************************************************/
- //粒子半径模式开始半径
- REDParticleStartRadiusTo* REDParticleStartRadiusTo::create(float fDuration, cocos2d::Vec2 gravity){
- REDParticleStartRadiusTo *ret = new (std::nothrow) REDParticleStartRadiusTo();
- if (ret)
- {
- if (ret->initWithDuration(fDuration, gravity))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- }
-
- return ret;
- }
- bool REDParticleStartRadiusTo::initWithDuration(float fDuration, cocos2d::Vec2 folatVar){
- if (ActionInterval::initWithDuration(fDuration))
- {
- _endFloatVar = folatVar;
- return true;
- }
- else
- {
- return false;
- }
- }
- REDParticleStartRadiusTo* REDParticleStartRadiusTo::clone() const {
- // no copy constructor
- auto a = new (std::nothrow) REDParticleStartRadiusTo();
- a->initWithDuration(_duration, _endFloatVar);
- a->autorelease();
- return a;
- }
- REDParticleStartRadiusTo* REDParticleStartRadiusTo::reverse() const {
- CCASSERT(false, "reverse() is not supported in REDParticleStartRadiusTo");
- return nullptr;
- }
- void REDParticleStartRadiusTo::startWithTarget(cocos2d::Node *pNode) {
- ActionInterval::startWithTarget(pNode);
-
- float a = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getStartRadius();
- float aVar = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getStartRadiusVar();
- _startFloatVar = Vec2(a, aVar);
- _diffFloatVar = _endFloatVar - _startFloatVar;
- }
- void REDParticleStartRadiusTo::update(float time){
- auto par = dynamic_cast<ZMLCCParticleSystem*>(_target);
- CCASSERT(par != nullptr, "REDParticleSpeedTo 只支持 ZMLCCParticleSystem");
- auto floatVar = _startFloatVar + (_diffFloatVar * time);
- par->setStartRadius(floatVar.x);
- par->setStartRadiusVar(floatVar.y);
- }
- /************************************************************
- REDParticleEndRadiusTo
- ************************************************************/
- //粒子半径模式结束半径
- REDParticleEndRadiusTo* REDParticleEndRadiusTo::create(float fDuration, cocos2d::Vec2 gravity){
- REDParticleEndRadiusTo *ret = new (std::nothrow) REDParticleEndRadiusTo();
- if (ret)
- {
- if (ret->initWithDuration(fDuration, gravity))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- }
-
- return ret;
- }
- bool REDParticleEndRadiusTo::initWithDuration(float fDuration, cocos2d::Vec2 folatVar){
- if (ActionInterval::initWithDuration(fDuration))
- {
- _endFloatVar = folatVar;
- return true;
- }
- else
- {
- return false;
- }
- }
- REDParticleEndRadiusTo* REDParticleEndRadiusTo::clone() const {
- // no copy constructor
- auto a = new (std::nothrow) REDParticleEndRadiusTo();
- a->initWithDuration(_duration, _endFloatVar);
- a->autorelease();
- return a;
- }
- REDParticleEndRadiusTo* REDParticleEndRadiusTo::reverse() const {
- CCASSERT(false, "reverse() is not supported in REDParticleEndRadiusTo");
- return nullptr;
- }
- void REDParticleEndRadiusTo::startWithTarget(cocos2d::Node *pNode) {
- ActionInterval::startWithTarget(pNode);
-
- float a = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getEndRadius();
- float aVar = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getEndRadiusVar();
- _startFloatVar = Vec2(a, aVar);
- _diffFloatVar = _endFloatVar - _startFloatVar;
- }
- void REDParticleEndRadiusTo::update(float time){
- auto par = dynamic_cast<ZMLCCParticleSystem*>(_target);
- CCASSERT(par != nullptr, "REDParticleSpeedTo 只支持 ZMLCCParticleSystem");
- auto floatVar = _startFloatVar + (_diffFloatVar * time);
- par->setEndRadius(floatVar.x);
- par->setEndRadiusVar(floatVar.y);
- }
- /************************************************************
- REDParticleRotatePerSecondTo
- ************************************************************/
- //粒子速度
- REDParticleRotatePerSecondTo* REDParticleRotatePerSecondTo::create(float fDuration, cocos2d::Vec2 gravity){
- REDParticleRotatePerSecondTo *ret = new (std::nothrow) REDParticleRotatePerSecondTo();
- if (ret)
- {
- if (ret->initWithDuration(fDuration, gravity))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- }
-
- return ret;
- }
- bool REDParticleRotatePerSecondTo::initWithDuration(float fDuration, cocos2d::Vec2 folatVar){
- if (ActionInterval::initWithDuration(fDuration))
- {
- _endFloatVar = folatVar;
- return true;
- }
- else
- {
- return false;
- }
- }
- REDParticleRotatePerSecondTo* REDParticleRotatePerSecondTo::clone() const {
- // no copy constructor
- auto a = new (std::nothrow) REDParticleRotatePerSecondTo();
- a->initWithDuration(_duration, _endFloatVar);
- a->autorelease();
- return a;
- }
- REDParticleRotatePerSecondTo* REDParticleRotatePerSecondTo::reverse() const {
- CCASSERT(false, "reverse() is not supported in REDParticleSpeedTo");
- return nullptr;
- }
- void REDParticleRotatePerSecondTo::startWithTarget(cocos2d::Node *pNode) {
- ActionInterval::startWithTarget(pNode);
-
- float a = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getRotatePerSecond();
- float aVar = dynamic_cast<ZMLCCParticleSystem*>(pNode)->getRotatePerSecondVar();
- _startFloatVar = Vec2(a, aVar);
- _diffFloatVar = _endFloatVar - _startFloatVar;
- }
- void REDParticleRotatePerSecondTo::update(float time){
- auto par = dynamic_cast<ZMLCCParticleSystem*>(_target);
- CCASSERT(par != nullptr, "REDParticleSpeedTo 只支持 ZMLCCParticleSystem");
- auto floatVar = _startFloatVar + (_diffFloatVar * time);
- par->setRotatePerSecond(floatVar.x);
- par->setRotatePerSecondVar(floatVar.y);
- }
- /************************************************************
- REDEaseInstant
- ************************************************************/
- REDEaseInstant* REDEaseInstant::create(ActionInterval *pAction)
- {
- REDEaseInstant *pRet = new (std::nothrow) REDEaseInstant();
- if (pRet && pRet->initWithAction(pAction))
- {
- pRet->autorelease();
- }
- else
- {
- CC_SAFE_RELEASE_NULL(pRet);
- }
-
- return pRet;
- }
- REDEaseInstant* REDEaseInstant::clone() const
- {
- // no copy constructor
- auto a = new (std::nothrow) REDEaseInstant();
- a->initWithAction(_inner);
- a->autorelease();
- return a;
- }
- REDEaseInstant* REDEaseInstant::reverse() const
- {
- return REDEaseInstant::create(_inner->reverse());
- }
- void REDEaseInstant::update(float dt)
- {
- if (dt < 0)
- {
- _inner->update(0);
- }
- else
- {
- _inner->update(1);
- }
- }
- /************************************************************
- EaseBezierByTimeAction
- ************************************************************/
- float crt(float v) {
- if (v < 0) {
- return -pow(-v, 1 / 3.0);
- } else {
- return pow(v, 1 / 3.0);
- }
- }
- float max(float a, float b){
- return a > b ? a : b;
- }
- float cardano(float xx1, float xx2, float x) {
- float pa = x - 0;
- float pb = x - xx1;
- float pc = x - xx2;
- float pd = x - 1; // to [t^3 + at^2 + bt + c] form:
-
- float pa3 = pa * 3;
- float pb3 = pb * 3;
- float pc3 = pc * 3;
- float d = -pa + pb3 - pc3 + pd;
- float rd = 1 / d;
- float r3 = 1 / 3.0;
- float a = (pa3 - 6 * pb + pc3) * rd;
- float a3 = a * r3;
- float b = (-pa3 + pb3) * rd;
- float c = pa * rd;
- // then, determine p and q:
- float p = (3 * b - a * a) * r3;
- float p3 = p * r3;
- float q = (2 * a * a * a - 9 * a * b + 27 * c) / 27.0;
- float q2 = q / 2.0;
- // and determine the discriminant:
- float discriminant = q2 * q2 + p3 * p3 * p3;
- // and some reserved variables
- float u1;
- float v1;
- float x1;
- float x2;
- float x3; // If the discriminant is negative, use polar coordinates
- // to get around square roots of negative numbers
- if (discriminant < 0) {
- float mp3 = -p * r3;
- float mp33 = mp3 * mp3 * mp3;
- float r = sqrt(mp33);
- // compute cosphi corrected for IEEE float rounding:
- float t = -q / (2.0 * r);
- float cosphi = t < -1 ? -1 : t > 1 ? 1 : t;
- float phi = acos(cosphi);
- float crtr = crt(r);
- float t1 = 2 * crtr;
- float tau = 2 * M_PI;
- x1 = t1 * cos(phi * r3) - a3;
- x2 = t1 * cos((phi + tau) * r3) - a3;
- x3 = t1 * cos((phi + 2 * tau) * r3) - a3; // choose best percentage
-
- x1 = (float)((int)(x1*10000)/10000.0);
- x2 = (float)((int)(x2*10000)/10000.0);
- x3 = (float)((int)(x3*10000)/10000.0);
-
- if (0 <= x1 && x1 <= 1) {
- if (0 <= x2 && x2 <= 1) {
- if (0 <= x3 && x3 <= 1) {
- return max(max(x1, x2), x3);
- } else {
- return max(x1, x2);
- }
- } else if (0 <= x3 && x3 <= 1) {
- return max(x1, x3);
- } else {
- return x1;
- }
- } else {
- if (0 <= x2 && x2 <= 1) {
- if (0 <= x3 && x3 <= 1) {
- return max(x2, x3);
- } else {
- return x2;
- }
- } else {
- return x3;
- }
- }
- } else if (discriminant == 0) {
- u1 = q2 < 0 ? crt(-q2) : -crt(q2);
- x1 = 2 * u1 - a3;
- x2 = -u1 - a3; // choose best percentage
-
- if (0 <= x1 && x1 <= 1) {
- if (0 <= x2 && x2 <= 1) {
- return max(x1, x2);
- } else {
- return x1;
- }
- } else {
- return x2;
- }
- } // one real root, and two imaginary roots
- else {
- float sd = sqrt(discriminant);
- u1 = crt(-q2 + sd);
- v1 = crt(q2 + sd);
- x1 = u1 - v1 - a3;
- return x1;
- }
- }
- /// 贝塞尔曲线的计算,200710 by zml
- /// @param x1 起始控制点的X
- /// @param y1 起始控制点的Y
- /// @param x2 结束控制点的X
- /// @param y2 结束控制点的Y
- /// @param x 输入的时间
- /// @return 更新后的时间
- float bezierByTime( float x1, float y1, float x2, float y2, float x ){
- float percent = cardano(x1, x2, x); // t
- return ((1 - percent) * (y1 + (y2 - y1) * percent) * 3 + percent * percent) * percent;
- }
- EaseBezierByTimeAction* EaseBezierByTimeAction::create(cocos2d::ActionInterval* action)
- {
- EaseBezierByTimeAction *ret = new (std::nothrow) EaseBezierByTimeAction();
- if (ret && ret->initWithAction(action))
- {
- ret->autorelease();
- return ret;
- }
- delete ret;
- return nullptr;
- }
- void EaseBezierByTimeAction::setBezierParamer( float p0, float p1, float p2, float p3)
- {
- _p0 = p0;
- _p1 = p1;
- _p2 = p2;
- _p3 = p3;
- }
- EaseBezierByTimeAction* EaseBezierByTimeAction::clone() const
- {
- // no copy constructor
- if (_inner)
- {
- auto ret = EaseBezierByTimeAction::create(_inner->clone());
- if (ret)
- {
- ret->setBezierParamer(_p0,_p1,_p2,_p3);
- }
- return ret;
- }
- return nullptr;
- }
- void EaseBezierByTimeAction::update(float time)
- {
- _inner->update(bezierByTime(_p0,_p1,_p2,_p3,time));
- }
- EaseBezierByTimeAction* EaseBezierByTimeAction::reverse() const
- {
- EaseBezierByTimeAction* reverseAction = EaseBezierByTimeAction::create(_inner->reverse());
- reverseAction->setBezierParamer(_p3,_p2,_p1,_p0);
- return reverseAction;
- }
- #pragma mark - RedBakeAnimationInstantAction
- RedBakeAnimationInstantAction* RedBakeAnimationInstantAction::create(const RedBakeNodeFrame& frame) {
- auto ret = new (std::nothrow) RedBakeAnimationInstantAction();
- if (ret && ret->init(frame)) {
- ret->autorelease();
- return ret;
- }
-
- delete ret;
- ret = nullptr;
- return nullptr;
- }
- bool RedBakeAnimationInstantAction::init(const RedBakeNodeFrame& frame) {
- _bakeFrame = frame;
- return true;
- }
- void RedBakeAnimationInstantAction::update(float time) {
- auto bakeNode = dynamic_cast<RedBakeNode*>(_target);
-
- if (bakeNode == nullptr) {
- return;
- }
-
- if (_bakeFrame.animationName.empty()) {
- return;
- }
-
- bakeNode->playAnimation(_bakeFrame.animationName, _bakeFrame.loop);
- }
- RedBakeAnimationInstantAction* RedBakeAnimationInstantAction::clone() const {
- auto ret = new (std::nothrow) RedBakeAnimationInstantAction();
- if (ret && ret->init(_bakeFrame)) {
- ret->autorelease();
- return ret;
- }
- delete ret;
- ret = nullptr;
- return nullptr;
- }
- RedBakeAnimationInstantAction* RedBakeAnimationInstantAction::reverse() const {
- return this->clone();
- }
- }
|