Hi everyone. I’m new with cocos2d-x, I’m programming my first game but I facing a problem that don’t know how to resolve it.
I have a main character in my fighter game. My character need to create an effect like he is strong breathing. To do that I had seperate character to 3 parts( 3 sprites ): head, body, and leg. Then add 3 part to one sprite called “mainCharacter”, My aim is to add loop (move up, move down) action to the head and body part to make the breath effect. It work pretty good.
My problem is the “mainCharacter” need to run “kick left” and “kick right” animation when user tap to left or right screen side. I have designed the sprite frames animation for each action. But I don’t know how to make “mainCharacter” switch from “breath” to “kick left” or “kick right” animation then return back to “breath” action after done the kick action.
Any one have a suggestion on this? I really appreciate your help!
Thanks you and sorry for my bad English.
You could stop your actions on head and body .
For example like this:
head->stopAllActions();
body->stopAllActions();
Maybe set them to their default position, if you want to:
head->setPosition(/*headDefaultPosition*/);
body->setPosition(/*bodyDefaultPosition*/);
Then run your kicking animation as a sequence with a lambda callback.
Maybe like this:
leg->runAction(Sequence::create(
Animate::create(/*kickLeftAnimation*/),
CallFunc::create([this]() {
// put here the code to start the breathing action:
head->runAction(RepeatForever::create(/*headBreathingAction*/));
body->runAction(RepeatForever::create(/*bodyBreathingAction*/));
}),
nullptr)
);
Hi @mausmausgames . Thanks you for your great suggestion. But as I mentioned, I have created 3 children sprites then add it to a parent sprite(mainCharacter). So if I run action kick left ( the animation made from 2 images, each image is a hold character image, not only leg or body or head). If I run it from leg sprite. Then the body, head sprite still there, It make the game very ugly. I’m very headache on this for many days. Is there another way to do the breath action without separate the sprite for 3 parts? Please help me on this. I really appreciate!
Please post some code, then I can help you for sure…
So, just to summarize:
You have a breathe action, where you have your character separated in three sprites, and a kick action, where it’s only one sprite…
Hmmm…
You can turn off the visibility at any time:
head->setVisible(false);
body->setVisible(false);
And then turn it on again in the lambda function.
But seriously, I don’t think, mixing frame animation with the kind of animation you’re doing for your breathe action is such a good thing. Why don’t you create a breathe animation as a frame animation for the whole sprite and use just one sprite for your character?
Thanks you. it’s really good idea. Why can’t I think about it. I’ll try it now!