Hello,
I’ve been working on a cocos2dx project for some time. I’ve been using spritesheets and plists to run animations. Recently I’ve been trying to figure out how to use Cocos Studio’s embedded animation designer, which looks pretty awesome
I’ve managed to figure out how to load a node from CSB and then run an animation attached it from the timeline, like in this code:
Node* someNode = CSLoader::createNode("TutorialAnim.csb");
auto sprite = static_cast<Sprite*>(someNode->getChildByName("Sprite_1"));
_rootNode->addChild(sprite);
cocostudio::timeline::ActionTimeline *timeLine = CSLoader::createTimeline("TutorialAnim.csb");
timeLine->retain(); //released later on
sprite->runAction(timeLine);
timeLine->play("animation", true);
As you can see, I load and run the animation on the sprite from the same .csb file and it works. However, I’m wondering if there is a way to run the animation on any generic object, similiarily how you can achieve i with Animate::create()
and AnimationCache::getInstance()->getAnimation("")
Loading the animation from the timeline and running it on any other object either does not work, or crash with EXC_BAD_ACCESS, which is weird, as I retain the timeLine object, for example:
auto otherSprite = Sprite::createWithSpriteFrameName("someSpriteName.png"); //loads correctly, does not crash
_rootNode->addChild(otherSprite);
cocostudio::timeline::ActionTimeline *timeLine = CSLoader::createTimeline("TutorialAnim.csb");
timeLine->retain(); //released later on
otherSprite->runAction(timeLine);
timeLine->play("animation", true); //sometimes EXC_BAD_ACCESS, sometimes nothing
Is this expected that you can run ActionTimeline objects only on nodes related to the same CocosStudio file? Or is there some property that i should set on the ActionTimeline for it to work on other nodes? I tried setTarget()
, setOriginalTarget()
, resume()
etc. to no success.
So, in short: is there a way to run an ActionTimeline animations on generic objects not loaded from .csb?
Thanks in advance!