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 /** Delays execution of an action or inserts a pause in a {@link SequenceAction}. 20 * @author Nathan Sweet */ 21 public class DelayAction extends DelegateAction { 22 private float duration, time; 23 24 public DelayAction () { 25 } 26 27 public DelayAction (float duration) { 28 this.duration = duration; 29 } 30 31 protected boolean delegate (float delta) { 32 if (time < duration) { 33 time += delta; 34 if (time < duration) return false; 35 delta = time - duration; 36 } 37 if (action == null) return true; 38 return action.act(delta); 39 } 40 41 /** Causes the delay to be complete. */ 42 public void finish () { 43 time = duration; 44 } 45 46 public void restart () { 47 super.restart(); 48 time = 0; 49 } 50 51 /** Gets the time spent waiting for the delay. */ 52 public float getTime () { 53 return time; 54 } 55 56 /** Sets the time spent waiting for the delay. */ 57 public void setTime (float time) { 58 this.time = time; 59 } 60 61 public float getDuration () { 62 return duration; 63 } 64 65 /** Sets the length of the delay in seconds. */ 66 public void setDuration (float duration) { 67 this.duration = duration; 68 } 69 } 70