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.graphics.Color; 20 import com.badlogic.gdx.scenes.scene2d.Actor; 21 22 /** Sets the alpha for an actor's color (or a specified color), from the current alpha to the new alpha. Note this action 23 * transitions from the alpha at the time the action starts to the specified alpha. 24 * @author Nathan Sweet */ 25 public class AlphaAction extends TemporalAction { 26 private float start, end; 27 private Color color; 28 29 protected void begin () { 30 if (color == null) color = target.getColor(); 31 start = color.a; 32 } 33 34 protected void update (float percent) { 35 color.a = start + (end - start) * percent; 36 } 37 38 public void reset () { 39 super.reset(); 40 color = null; 41 } 42 43 public Color getColor () { 44 return color; 45 } 46 47 /** Sets the color to modify. If null (the default), the {@link #getActor() actor's} {@link Actor#getColor() color} will be 48 * used. */ 49 public void setColor (Color color) { 50 this.color = color; 51 } 52 53 public float getAlpha () { 54 return end; 55 } 56 57 public void setAlpha (float alpha) { 58 this.end = alpha; 59 } 60 } 61