Muhammad Awais Qamar
Muhammad Awais Qamar

Reputation: 33

How To run Animation and an Action of same sprite simultaneously in cocos2d-x

I have an Animation which is present in forever loop and i want to run an action with it. want to run both animation and action at same time.

For Example : Changing Ball Color (Animation) and Buncing it (Action) .

Upvotes: 0

Views: 636

Answers (2)

nin
nin

Reputation: 48

You can also call runAction() once for each action.

node->runAction(animationAction);
node->runAction(bounceAction);

Upvotes: 1

Pratik
Pratik

Reputation: 433

there are several ways to do it

1) you can use Spawn action

auto spawnAnimationAction = Spawn::create(colorAnimation, bounceAction, NULL);
ball->runAction(spawnAnimationAction);

2) you can create a ball Node and add ball sprite as a child to ball node. apply animation on ball sprite and bounce action on ball node.

auto ballNode = Node::create();
auto ballSprite = Sprite::create("filename.png" );
ballSprite->runAction(colorAnimation);
ballNode->addChild(ballSprite);
ballNode->runAction(bounceAction);

3)You can create your own custom Action class which will handle both color animation and bounce action

Upvotes: 1

Related Questions