Cocos2dx <Basic> Actions(3)

<Joint Action>

Combine independent actions into a variety of associated actions. (actions performed in sequence, actions performed in reverse, and actions performed at the same time)

(Sequence action: actions performed in sequence) ----->Sequence implements sequence actions.

Use functions to create sequence actions: static Sequence* create(1 or more action objects, null) ----> Parameters: 1 or more action objects, terminated by null

        Size visibleSize = Director::getInstance()->getVisibleSize();
        auto size  = visibleSize / 2;
	auto moves = MoveTo::create(2, Vec2(size.width + 150, size.height));
	auto flipX = FlipX::create(true);
	auto seq = Sequence::create(moves,flipX,NULL);
	sprite->runAction(seq);

(Execute actions at the same time)----->Spawn implements actions at the same time

Use functions to create simultaneous actions: static Spawn* create(1 or more action objects, null) -----> Parameters: 1 or more action objects, terminated by null

	//Execute actions at the same time (magnify while moving)
	Size visibleSize = Director::getInstance()->getVisibleSize();
	auto size  = visibleSize / 2;
	auto moves = MoveTo::create(2, Vec2(size.width + 150, size.height));
	auto scale = ScaleTo :: create (2,3);
	auto seq = Spawn::create(moves,scale,NULL);
	sprite->runAction(seq);
When multiple actions are placed in one sprite, the actions will be superimposed; it is best to superimpose different actions

(Reverse action: The action is executed once from the end to the beginning according to the original path) -----> The reverse method of the action class generates the reverse action of the original action.

Use a function to implement the reverse action of the original action: action object.reverse()

	// reverse action
	auto size =  visibleSize / 2;
	auto moves = MoveBy::create(2, Vec2(size.width + 150, size.height));
	auto sequence = Sequence::create(moves,moves->reverse(),NULL);
	sprite->runAction(sequence);

(Multiple repetitions)---->Create a class for repeated actions: Repeat()

Use functions to implement repeated actions: Repeat::create (repeat action object, times)

	auto size = visibleSize / 2;
	auto moves = MoveBy::create(2, Vec2(size.width + 150, size.height));
	auto sequence = Sequence::create(moves, moves->reverse(), NULL);
	sprite->runAction(Repeat::create(sequence,2));

(Keep repeating the action)---->Create a class that keeps repeating the action: RepeatForever()

Use a function to repeat the action: RepeatForever::create(action object);

(Delay execution action)---->Wait for a period of time to execute action: DelayTime

Use functions to implement delayed execution actions: DelayTime::create (the time for the delayed execution of the action)

	//delay the execution of the action
	auto size = visibleSize / 2;
	auto moves = MoveBy::create(2, Vec2(size.width + 150, size.height));
	auto time = DelayTime::create(2);
	auto sequence = Sequence::create(moves,time, moves->reverse(), NULL);
	sprite->runAction(sequence);

(copy of action)--->action.clone()

Duplication of Actions: Different objects perform the same action. All actions have clone().

Note: If you add an action to an object, do not add the action to another object, use clone()

	// Both objects perform the same action
	auto move = MoveBy::create(2,Vec2(100,0));
	sprite->runAction(move);
	auto move1 = (MoveBy*)move->clone();
	sprite1->runAction(move1);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325580987&siteId=291194637