MCPcopy Create free account
hub / github.com/axmolengine/axmol / initWithAnimation

Method initWithAnimation

core/2d/ActionInterval.cpp:2480–2514  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2478}
2479
2480bool Animate::initWithAnimation(Animation* animation)
2481{
2482 AXASSERT(animation != nullptr, "Animate: argument Animation must be non-nullptr");
2483 if (animation == nullptr)
2484 {
2485 AXLOGE("Animate::initWithAnimation: argument Animation must be non-nullptr");
2486 return false;
2487 }
2488
2489 float singleDuration = animation->getDuration();
2490
2491 if (ActionInterval::initWithDuration(singleDuration * animation->getLoops()))
2492 {
2493 _nextFrame = 0;
2494 setAnimation(animation);
2495 _origFrame = nullptr;
2496 _executedLoops = 0;
2497
2498 _splitTimes->reserve(animation->getFrames().size());
2499
2500 float accumUnitsOfTime = 0;
2501 float newUnitOfTimeValue = singleDuration / animation->getTotalDelayUnits();
2502
2503 auto& frames = animation->getFrames();
2504
2505 for (auto&& frame : frames)
2506 {
2507 float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration;
2508 accumUnitsOfTime += frame->getDelayUnits();
2509 _splitTimes->emplace_back(value);
2510 }
2511 return true;
2512 }
2513 return false;
2514}
2515
2516void Animate::setAnimation(ax::Animation* animation)
2517{

Callers 1

createMethod · 0.80

Calls 5

setAnimationFunction · 0.85
getDurationMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected