   Animation/Sprite Class (DirectX) *pulls hair out*
  Hey everyone, this is my first time writing an Animation/Sprite class using OOP in a game environment.  I wrote up the class in a couple hours but I've been debugging for a couple of days.  So first of all, what is happening?  Well, I've manually defined some animations.  When I just let the program run the default animation runs fine.  When I change the animation type the animation plays (so it isn't the animation).  The animation is based on the movement type. Whenever I try to use input from the keyboard (to move the player) the animation should change but instead the character disappears.Here are the classes:EntityPlayer (inherits from Entity)sHandlerAnimationBelow I'm going to put a BUNCH of code... so hopefully I dont put too much to scare you all off.gameGlobals.h:// this just takes care of some global variables that are used throughout the classes#ifndef gameGlobals_H#define gameGlobals_H#include "windows.h"// some code snippetedstruct sequence{DWORD delay;  // how much delay this particular image in the animation hasRECT selection;  // the rectangle for selection based on what image is chosenfloat width;  // width of the stand still imagefloat height;  // height of the stand still imageDWORD startTime;  // the time that the value startedcollisionBox cbA;  // collision box for attackcollisionBox cbD;  // collision box for defense};enum movement{IDLE,WALKING,//RUNNING,ATTACK1,  // base attack 1ATTACK2,  // base attack 2ATTACK3,  // base attack 3ATTACK4,  // kick 1ATTACK5,  // kick 2ATTACK6,  // kick 3ATTACK7,  // special 1ATTACK8,  // special 2ATTACK9,  // special 3ATTACK10,JUMP};#endifAnimation.h:#ifndef ANIMATION_H#define ANIMATION_H#include "gameGlobals.h"#include <vector>class animation{  private:    std::vector<sequence> s; // a vector of sequences    std::vector<sequence>::iterator it; // the iterator    movement type;  public:    RECT getImgRect();    void update();void reset();    void addToSeq(sequence seq);    void setType(movement t);    movement getType();};#endifsHandler.h:#ifndef sHandler_H#define sHandler_H#include <d3d9.h>#include <d3dx9core.h>#include "animation.h"#include <vector>class sHandler{private:std::vector<animation> ani;    std::vector<animation>::iterator it;    LPD3DXSPRITE sSprite;    LPDIRECT3DTEXTURE9 sTexture;bool firstTime;  // uses reset once//int currentAnimation;public:sHandler();void addAnimation(animation a);void update();LPD3DXSPRITE getS();  // get the sprite object    LPDIRECT3DTEXTURE9 getT();  // get the texture    RECT getR();  // get the rectangle to the imagevoid setType(movement typ);movement getType();    void findAnimation(movement ty);    void loadGraphics(char* filename, LPDIRECT3DDEVICE9 g_pd3dDevice);};#endifsHandler.cpp (only important stuff):void sHandler::findAnimation(movement ty){  for(std::vector<animation>::iterator ait = ani.begin(); ait != ani.end(); ait++)  {  movement t = ait->getType();  // get the movement type    if(ty == t)    { // set the class's iterator to the iterator that has the matching movement it = ait;    }  }}void sHandler::update(){if(firstTime == true){it->reset();//currentAnimation = 0;firstTime = false;}it->update();//ani[currentAnimation].update();}animation.cpp (important stuff):RECT animation::getImgRect(){  return it->selection;}void animation::update(){ if((GetTickCount() - it->startTime) >= it->delay)  {  //ofstream output;  //output.open("errorLog.txt", ios::app);  //output << type << endl;  //output.close();    if(it != s.end())    { it++;    }    if(it == s.end())    {//it = s.begin();this->reset();    }it->startTime = GetTickCount();  }}void animation::addToSeq(sequence seq){  DWORD tNow = GetTickCount();  seq.startTime = tNow;  s.push_back(seq);}void animation::reset(){it = s.begin();}Entity.cpp (only the draw function):void Entity::draw(){sh.findAnimation(type);entitySprite = sh.getS();entityTexture = sh.getT();// begin sprite objectentitySprite->Begin(D3DXSPRITE_ALPHABLEND);// if the entity is active then draw itD3DXVECTOR2 charPos;charPos.x = posX;charPos.y = posY;// create the character matrixD3DXMATRIX charMat;// if the entity is facing right, no need to flipif(right == true){D3DXVECTOR2 scaling(-1.0, 1.0);D3DXVECTOR2 scaleCenter(width/2, height/2);D3DXMatrixTransformation2D(&charMat, &scaleCenter, 0.0, &scaling, NULL, NULL, &charPos);}else{D3DXVECTOR2 scaling(1.0, 1.0);D3DXVECTOR2 scaleCenter(width/2, height/2);D3DXMatrixTransformation2D(&charMat, &scaleCenter, 0.0, &scaling, NULL, NULL, &charPos);}image = sh.getR();entitySprite->SetTransform(&charMat);entitySprite->Draw(entityTexture, &image, NULL, NULL, D3DCOLOR_ARGB(255,255,255,255));D3DXMatrixIdentity(&charMat);entitySprite->SetTransform(&charMat);// end the spriteentitySprite->End();sh.update();}Player.cpp (only the input function):void Player::Input(){// type is the type of animationif(KEYSTATE(VK_UP))//if(true == true){velY = -1;type = WALKING;}else if(KEYSTATE(VK_DOWN)){velY = 1;type = WALKING;}else if(KEYSTATE(VK_RIGHT)){right = false;velX = 1;type = WALKING;}else if(KEYSTATE(VK_LEFT)){right = true;velX = -1;type = WALKING;}else if(KEYSTATE(VK_SPACE)){// push enemy backtype = ATTACK1;}//type = IDLE;}I know this is pretty long, but I've been at it for a long time and I have NO idea what I'm doing wrong.  If any1 could help I'd be very appreciative.   
  Its pretty long and I must admit I didn't read it all, but have you tried debugging it?Something you could try is replace your idle animation by your walk animation, just to make sure your animation works.  If this works then it might be a problem with your input code that moves the sprite around?Hope this helps   ;  I did try debugging.  And I did try replacing the IDLE animation with the walk animation has stated in the first couple of lines (it's ok I don't blame ya for missing that).And the actual input code works, because it moves the player around.  What I'm thinking (but can't seem to come to a conclusion about) is that my findAnimation (in the sHandler) isn't doing its job correctly.  But wheN i debug it looks like it does!Has anyone else used a simlar setup to mine?  How did you "link" your animation to your sprite handler?  Basically after I change the movement type I need to tell the program to choose teh animation that has that type.  I swear that's what I'm doing but... I dunno.Thanks for your reply!   ;  Something you could do is change your vector to a std::map< movement type, sprite >...Also, findAnimation should either assert or return false if it can't find the desired animation.I don't have much time right now, but I'll check this thread again later tonight to see if you got it or not :)CheersEric   ;  i switched to the map thing;  i definately like the style of that a lot betterhowever, that doesnt' fix the issue :-pi'm still workin on it... i'll try to update the code in a lil whileEDIT: i got two animations to work, for some reason the WALKING animation isn't working... not quite sure why;  it turned out i was using a different way of inserting for the map container and that's one reason it wasn't working (I think)i'll try to figure it out tomorrow and maybe post some code[Edited by - -justin- on May 26, 2006 10:25:29 PM]