I'm trying to make a sequence which has 3 RotateBy actions.
1st RotateBy action with ANCHOR_MIDDLE_TOP
2nd RotateBy action with ANCHOR_MIDDLE
3rd RotateBy action with ANCHOR_MIDDLE_BOTTOM
But, I don't know how to run this sequence in the following order
mySprite->setAnchorPoint(Point::ANCHOR_MIDDLE_TOP);
mySprite->setAnchorPoint(Point::ANCHOR_MIDDLE);
mySprite->setAnchorPoint(Point::ANCHOR_MIDDLE_BOTTOM);
And Sequence::create takes only actions.
You can use CallFunc
as an action, and call a function that changes the anchor point of your sprite. Something like this:
cocos2d::Sequence::create(cocos2d::RotateBy::create(1.0f, 90.0f),
cocos2d::CallFunc::create(MySprite::changeAnchorPoint),
cocos2d::RotateBy::create(1.0f, 90.0f),
cocos2d::CallFunc::create(MySprite::changeAnchorPoint),
cocos2d::RotateBy::create(1.0f, 90.0f),
cocos2d::CallFunc::create(MySprite::changeAnchorPoint));
Edit: to send a parameter you should be able to write something like this:
cocos2d::CallFunc::create([mySprite]() {
mySprite->setAnchorPoint(Point::ANCHOR_MIDDLE_TOP);
});
Note: CallFunc wants a function with no parameters, but you can get around that by capturing your object you'd like to use in the function using the c++11 lambda syntax.