Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Basic C++ Animation Class Not Working!

Name: Anonymous 2007-04-13 0:28 ID:n4ihaNU4

All right.. im trying to make a generic animation class for a small game im working on for PSP (homebrew, whee!), but im still pretty rusty when it comes to C++. To me it seems like this class SHOULD work fine, but for some reason its not!


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;
  }
};


Then i do:


Animation *animator = new Animation(0,255,50,ANIM_EASEIN); // Create new animator for alpha
animator->Start();

...

//Then, every frame,
animator->Step();

// Then when drawing my sprite, i use animator->currentValue for the alpha

What should happen is i should get a value that increases up to 255 on the 50th frame, but what is happening is I just get '255' constantly! The code looks fine to me, ive been messing with it all night!

Anyone got an idea why it wont work?

Name: Anonymous 2007-04-16 1:15 ID:n8pvcv48

try putting your balls in mineral water, recompile. if not, rewrite the class entirely several times over, put your balls in mineral water, then compile again.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List