What’s the difference between the two sources below?
auto move = MoveBy::create(0.3f, Vec2(0, 100));
auto moveEaseIn = EaseOut::create(move->clone(), 1);
auto move = MoveBy::create(0.3f, Vec2(0, 100));
auto moveEaseIn = EaseOut::create(move, 1);
Well, there will be no difference in UI but there will be extra copy of move action in memory in first case.
So what’s the benefit about using a clone?
Clone() is used to create a copy of an action so that it can be used in another action.
auto move = MoveBy::create(0.3f, Vec2(0, 100));
auto moveEaseIn = EaseOut::create(move, 1); // move is already used in this action
If I want to use the same move action, then I must have to create it suing clone().
anySprite->runAction(move->clone()); // need to clone as it is already used in moveEaseIn
If you don’t make it clone() here, there may be some strange move animation.
1 Like