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

Pages: 1-

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-13 2:27 ID:wusk1XXR

You are doing integer math at some parts, resulting in rounding errors, probably the float n = frame/length bit, which should be float n = (float)frame/(float)length to force floating point division.

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.

Name: Anonymous 2007-04-16 5:05 ID:0TZsiLKT

>>3
Actually laughed out loud

Name: Anonymous 2007-04-16 9:53 ID:o9InPmCz

How about you stop using shitty coding conventions and do the following:
comment your fucking code
tab indent it properly
define a class interface in a header file
put all your functions for this class in a cpp implementation file
write a test plan
write a test program that uses this class, it can even be executed on your pc instead of the psp just for testing.

Name: Anonymous 2007-04-16 9:55 ID:o9InPmCz

SPACES BETWEEN YOUR FUNCTIONS MAKE IT MUCH EASIER TO READ AND DEBUG LATER.

Name: Anonymous 2007-04-16 10:03 ID:ivKviO+g

>>5
>How about you stop using C++ and do the following:
>learn Haskell

FIXED

Name: Anonymous 2007-04-16 10:08 ID:o9InPmCz

>>7
That's for research retard, not for game homebrewing.
Functional languages can go far, but for games, they're essential.

Name: Anonymous 2007-04-16 10:10 ID:o9InPmCz

>>8
Shit, I meant that OOP is essential for games.

Name: Anonymous 2007-04-16 11:09 ID:80kphi3Q

>>9
You think Haskell doesn't have OOP?

Haskell has everything, EVERYTHING!!

Name: Anonymous 2007-04-16 11:25 ID:o9InPmCz

>>10
But it's still for research and academia.
Now quit trolling and gb2/b/

Name: Anonymous 2007-04-16 11:50 ID:Blv70iGm

Haskell's type system makes it trivial to make embedded domain specific languages, which are superior to OO by magnitudes.

Name: Anonymous 2007-04-16 11:57 ID:ivKviO+g

Name: Anonymous 2007-04-16 12:00 ID:80kphi3Q

>>11
/b/?  Good Sir, I take insult to you proposing that I visit the cesspool of faggotry which is /b/, why it is filled to the brim not unlike our /lounge/.

Name: Anonymous 2007-04-16 12:14 ID:0TZsiLKT

>>5
tab indent it properly
See why it's good to force indentation?

>>9
1. Most functional languages feature OO.
2. Those who don't (and those who do) are powerful enough to let you create your own object system, something no OO faplanguage (C++, Java, etc.) can ever dream of. In fact, OO in functional languages is usually just an extension, not always deemed necessary.
3. Objects are poor man's closures. Functional languages have closures, which supersede object systems functionality.

Name: Anonymous 2007-04-16 12:45 ID:aea3IwW/

>>9
You're an idiot! C++ isn't even object oriented. See Smalltalk.

Name: Anonymous 2007-04-16 15:35 ID:47MfEh1X

I can do this in batch:

@echo off
echo Hello World!

Name: Anonymous 2007-04-16 15:43 ID:rz0idbqG

>>3-17
What the fuck is wrong with you people, I gave him the answer he was looking for in >>2, so there is no reason to keep posting in this thread.

Name: Anonymous 2007-04-17 2:01 ID:nD0CjYHh

>>18
This is /prog/, you retard.

Name: Anonymous 2007-04-18 11:33 ID:oskfHvgn

>>18
I can do this in batch:

@echo off
echo Hello World!

Name: Anonymous 2009-01-14 15:13

lol

Name: Anonymous 2011-01-31 21:33

<-- check em dubz

Name: tray 2012-03-15 1:36

Name: Anonymous 2012-03-15 2:00

Haskell is a fucking joke, nobody uses it.

Name: Anonymous 2012-03-15 4:26

C++
Haskell

My usual game - catch the dog, feeding it, earn the trust, and then tie, wear a muzzle, beaten and thrown into the basement, not to feed it a week and all this time to fuck in the ass. Females become tame very quickly, snapping dogs for a long time and get a boot to the kidneys, some of them deserve a break and the backbone of a slow death. And when after that I untied her, and feed, do you think she grabs my throat? Maybe someday it would happen, but so far everything as a tail sweeping the floor, walking on bent and gently lick the cock, looking into her eyes. It was only when I get tired of the cattle, I am the soul of a wide belt, pierce the jugular vein of sharpening, or harassment of isoniazid, watching the agony and sometimes fuck before his death, it's nice to feel muscle spasms, and sometimes after, feeling the heat away from the fresh corpse .

Name: Anonymous 2012-03-15 14:26

>>18
ONE WORD, THE FORCED REPLY TO EVERY POST. THREAD OVER.

Name: Sgt.Kabu芋虖kiman설酥 2012-05-29 0:10

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

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