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.utils.Align;
     20 
     21 /** Moves an actor from its current position to a specific position.
     22  * @author Nathan Sweet */
     23 public class MoveToAction extends TemporalAction {
     24 	private float startX, startY;
     25 	private float endX, endY;
     26 	private int alignment = Align.bottomLeft;
     27 
     28 	protected void begin () {
     29 		startX = target.getX(alignment);
     30 		startY = target.getY(alignment);
     31 	}
     32 
     33 	protected void update (float percent) {
     34 		target.setPosition(startX + (endX - startX) * percent, startY + (endY - startY) * percent, alignment);
     35 	}
     36 
     37 	public void reset () {
     38 		super.reset();
     39 		alignment = Align.bottomLeft;
     40 	}
     41 
     42 	public void setPosition (float x, float y) {
     43 		endX = x;
     44 		endY = y;
     45 	}
     46 
     47 	public void setPosition (float x, float y, int alignment) {
     48 		endX = x;
     49 		endY = y;
     50 		this.alignment = alignment;
     51 	}
     52 
     53 	public float getX () {
     54 		return endX;
     55 	}
     56 
     57 	public void setX (float x) {
     58 		endX = x;
     59 	}
     60 
     61 	public float getY () {
     62 		return endY;
     63 	}
     64 
     65 	public void setY (float y) {
     66 		endY = y;
     67 	}
     68 
     69 	public int getAlignment () {
     70 		return alignment;
     71 	}
     72 
     73 	public void setAlignment (int alignment) {
     74 		this.alignment = alignment;
     75 	}
     76 }
     77