| 2645 | //------------------------------------------------------------------ |
| 2646 | |
| 2647 | SpriteBatchNodeChildren::SpriteBatchNodeChildren() |
| 2648 | { |
| 2649 | auto s = Director::getInstance()->getWinSize(); |
| 2650 | |
| 2651 | // parents |
| 2652 | auto batch = SpriteBatchNode::create("animations/grossini.png", 50); |
| 2653 | |
| 2654 | addChild(batch, 0, kTagSpriteBatchNode); |
| 2655 | |
| 2656 | SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist"); |
| 2657 | |
| 2658 | auto sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png"); |
| 2659 | sprite1->setPosition(Vec2(s.width / 3, s.height / 2)); |
| 2660 | |
| 2661 | auto sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png"); |
| 2662 | sprite2->setPosition(Vec2(50.0f, 50.0f)); |
| 2663 | |
| 2664 | auto sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png"); |
| 2665 | sprite3->setPosition(Vec2(-50.0f, -50.0f)); |
| 2666 | |
| 2667 | batch->addChild(sprite1); |
| 2668 | sprite1->addChild(sprite2); |
| 2669 | sprite1->addChild(sprite3); |
| 2670 | |
| 2671 | // BEGIN NEW CODE |
| 2672 | Vector<SpriteFrame*> animFrames(14); |
| 2673 | char str[100] = {0}; |
| 2674 | for (int i = 1; i < 15; i++) |
| 2675 | { |
| 2676 | fmt::format_to_z(str, "grossini_dance_{:02d}.png", i); |
| 2677 | auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(str); |
| 2678 | animFrames.pushBack(frame); |
| 2679 | } |
| 2680 | |
| 2681 | auto animation = Animation::createWithSpriteFrames(animFrames, 0.2f); |
| 2682 | sprite1->runAction(RepeatForever::create(Animate::create(animation))); |
| 2683 | // END NEW CODE |
| 2684 | |
| 2685 | auto action = MoveBy::create(2, Vec2(200.0f, 0.0f)); |
| 2686 | auto action_back = action->reverse(); |
| 2687 | auto action_rot = RotateBy::create(2.0f, 360.0f); |
| 2688 | auto action_s = ScaleBy::create(2.0f, 2.0f); |
| 2689 | auto action_s_back = action_s->reverse(); |
| 2690 | |
| 2691 | auto seq2 = action_rot->reverse(); |
| 2692 | sprite2->runAction(RepeatForever::create(seq2)); |
| 2693 | |
| 2694 | sprite1->runAction(RepeatForever::create(action_rot)); |
| 2695 | sprite1->runAction(RepeatForever::create(Sequence::create(action, action_back, nullptr))); |
| 2696 | sprite1->runAction(RepeatForever::create(Sequence::create(action_s, action_s_back, nullptr))); |
| 2697 | } |
| 2698 | |
| 2699 | void SpriteBatchNodeChildren::onExit() |
| 2700 | { |
nothing calls this directly
no test coverage detected