1
votes

In my game, I need to rotate coin for that I am using ActionTween like below

auto animateTo=ActionTween::create(.4, "roll", 0.f, M_PI_2);
auto animateFrom=ActionTween::create(.4, "roll", M_PI_2, M_PI);
auto seq=Sequence::create(animateTo,animateFrom, NULL);
coin->runAction(seq); 

I have implemented the ActionTweenDelegate too like

class GameScene : Base, public ActionTweenDelegate

and implemented the method

void updateTweenAction(float value, const std::string& key);

But everytime I get

Assert failed: target must implement ActionTweenDelegate Assertion failed: (dynamic_cast(target)), function startWithTarget

I have tried to set startTarget as well like

animateTo->setOriginalTarget(this);
animateFrom->setOriginalTarget(this);

But no luck, nothing working it crashes everytime.

Please if anyone experienced the same thing, help.

Thanks.

1

1 Answers

2
votes

do this :

Inherit the ActionTweenDelegate (ActionTween's Protocol) to the class of the sprite on which you want to perform the ActionTween.

Also write

void updateTweenAction(float value, const std::string& key);

method in your class's .h & .cpp file.

Once the ActionTween runs update the sprite's key property with value;

Example :

MySprite *sprite = MySprite::create();
sprite->runAction(ActionTween::create(1.0, "scaleX", 1.0, 0.0))

and in MySprite.cpp

void updateTweenAction(float value, const std::string& key) {
    this->setScaleX(value);
}

make sure that key "scaleX" in tween constructor and in callback must be same.