Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Transition{
- private float startV,endV;
- private long activeChange;
- private int speed;
- public Transition(float initalValue, int speed){
- this.speed=speed;
- setInstant(initalValue);
- }
- public void setInstant(float value){
- startV=endV=value;
- activeChange=System.currentTimeMillis()-speed;
- }
- public void setSpeed(int ms){
- speed=ms;
- }
- public void setGoal(float value){
- startV=get();
- endV=value;
- activeChange=System.currentTimeMillis();
- }
- public float get(){
- float precent=getPrecent();
- if(precent<0) return startV;
- if(precent>1) return endV;
- return startV+(endV-startV)*precent;
- }
- public boolean changing(){
- if(startV==endV) return false;
- float precent=getPrecent();
- return precent>0&&precent<1;
- }
- private float getPrecent(){
- long past=System.currentTimeMillis()-activeChange;
- if(past>speed) return 1;
- if(past<0) return 0;
- return (float)(((double)past)/speed);
- }
- }
Add Comment
Please, Sign In to add comment