------------------------------------------------------------------ SpriteHybrid ------------------------------------------------------------------
| 2553 | // |
| 2554 | //------------------------------------------------------------------ |
| 2555 | SpriteHybrid::SpriteHybrid() |
| 2556 | { |
| 2557 | auto s = Director::getInstance()->getWinSize(); |
| 2558 | |
| 2559 | // parents |
| 2560 | auto parent1 = Node::create(); |
| 2561 | auto parent2 = SpriteBatchNode::create("animations/grossini.png", 50); |
| 2562 | |
| 2563 | addChild(parent1, 0, kTagNode); |
| 2564 | addChild(parent2, 0, kTagSpriteBatchNode); |
| 2565 | |
| 2566 | // IMPORTANT: |
| 2567 | // The sprite frames will be cached AND RETAINED, and they won't be released unless you call |
| 2568 | // SpriteFrameCache::getInstance()->removeUnusedSpriteFrames); |
| 2569 | SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist"); |
| 2570 | |
| 2571 | // create 250 sprites |
| 2572 | // only show 80% of them |
| 2573 | for (int i = 0; i < 250; i++) |
| 2574 | { |
| 2575 | const int spriteIdx = random(1, 14); |
| 2576 | char str[25] = {0}; |
| 2577 | fmt::format_to_z(str, "grossini_dance_{:02d}.png", spriteIdx); |
| 2578 | auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(str); |
| 2579 | auto sprite = Sprite::createWithSpriteFrame(frame); |
| 2580 | parent1->addChild(sprite, i, i); |
| 2581 | |
| 2582 | float x = -1000; |
| 2583 | float y = -1000; |
| 2584 | if (AXRANDOM_0_1() < 0.2f) |
| 2585 | { |
| 2586 | x = AXRANDOM_0_1() * s.width; |
| 2587 | y = AXRANDOM_0_1() * s.height; |
| 2588 | } |
| 2589 | sprite->setPosition(Vec2(x, y)); |
| 2590 | |
| 2591 | auto action = RotateBy::create(4, 360); |
| 2592 | sprite->runAction(RepeatForever::create(action)); |
| 2593 | } |
| 2594 | |
| 2595 | _usingSpriteBatchNode = false; |
| 2596 | |
| 2597 | schedule(AX_CALLBACK_1(SpriteHybrid::reparentSprite, this), 2, "reparent_sprite_key"); |
| 2598 | } |
| 2599 | |
| 2600 | void SpriteHybrid::reparentSprite(float dt) |
| 2601 | { |
nothing calls this directly
no test coverage detected