Code: Select all
class Animation {
	private:
  int frame;
  float beginValue;
  float targetValue;
  int length;
  int animType;
	public:
  float currentValue;
  bool done;
  bool paused;
  Animation(float startNum, float endNum, int totalSteps, int type) {
  	Reset(startNum,endNum,totalSteps,type);
  }
  void Reset(float startNum, float endNum, int totalSteps, int type) { // Make object reusable
  	frame = 0;
  	done = false;
  	paused = true;
  	currentValue = startNum;
  	beginValue = startNum;
  	targetValue = endNum;
  	length = totalSteps;
  	animType = type;
  }
  void Start() {
  	paused = false;
  	done = false;
  }
  void Stop() {
  	frame = 0;
  	done = true;
  	currentValue = 0;
  	beginValue = 0;
  	targetValue = 0;
  	length = 0;
  }
  void Pause() {
  	paused = true;
  }
  void Unpause() {
  	paused = false;
  }
  float Step() {
  	if (paused || done) return currentValue;
  	frame++;
  	if (frame>=length) {
    done = true;
    currentValue = targetValue;
    return 0;
  	}
  	float delta = targetValue-beginValue;
  	switch (animType) {
    case ANIM_LINEAR:
    	// TODO: Other animations
    	break;
    case ANIM_EASEIN:
    	float n = frame/length;
    	currentValue = delta*n*n*n+beginValue;
    	return currentValue;
  	}
  	return currentValue;
  }
};
Code: Select all
Animation *animator = new Animation(0,255,50,ANIM_EASEIN); // Create new animator for alpha, 50 frames long, using ANIM_EASEIN
animator->Start();
...
//Then, every frame,
animator->Step();
// Then when drawing my sprite, i use animator->currentValue for the alpha
Anyone got an idea why it wont work?
