Home | History | Annotate | Download | only in actions
      1 /*******************************************************************************
      2  * Copyright 2011 See AUTHORS file.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *   http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  ******************************************************************************/
     16 
     17 package com.badlogic.gdx.scenes.scene2d.actions;
     18 
     19 import com.badlogic.gdx.scenes.scene2d.Action;
     20 import com.badlogic.gdx.utils.Pool;
     21 
     22 /** Executes a number of actions one at a time.
     23  * @author Nathan Sweet */
     24 public class SequenceAction extends ParallelAction {
     25 	private int index;
     26 
     27 	public SequenceAction () {
     28 	}
     29 
     30 	public SequenceAction (Action action1) {
     31 		addAction(action1);
     32 	}
     33 
     34 	public SequenceAction (Action action1, Action action2) {
     35 		addAction(action1);
     36 		addAction(action2);
     37 	}
     38 
     39 	public SequenceAction (Action action1, Action action2, Action action3) {
     40 		addAction(action1);
     41 		addAction(action2);
     42 		addAction(action3);
     43 	}
     44 
     45 	public SequenceAction (Action action1, Action action2, Action action3, Action action4) {
     46 		addAction(action1);
     47 		addAction(action2);
     48 		addAction(action3);
     49 		addAction(action4);
     50 	}
     51 
     52 	public SequenceAction (Action action1, Action action2, Action action3, Action action4, Action action5) {
     53 		addAction(action1);
     54 		addAction(action2);
     55 		addAction(action3);
     56 		addAction(action4);
     57 		addAction(action5);
     58 	}
     59 
     60 	public boolean act (float delta) {
     61 		if (index >= actions.size) return true;
     62 		Pool pool = getPool();
     63 		setPool(null); // Ensure this action can't be returned to the pool while executings.
     64 		try {
     65 			if (actions.get(index).act(delta)) {
     66 				if (actor == null) return true; // This action was removed.
     67 				index++;
     68 				if (index >= actions.size) return true;
     69 			}
     70 			return false;
     71 		} finally {
     72 			setPool(pool);
     73 		}
     74 	}
     75 
     76 	public void restart () {
     77 		super.restart();
     78 		index = 0;
     79 	}
     80 }
     81