   C++ DirectX sprite problem
  What I'm trying to do is make a simple Space Invaders game. The problem I'm having is with my enemy and player sprites.I'm trying to get my enemies move along the top of the screen, back and fourth, with the player sprite being controlled by the player along the bottom. When I run my program though, my player sprite moves along with my enemy sprite due to a reason I cannot seem to find.Could someone please run a fresh pair of eyes over my code and see what my eyes are refusing to?Load code// Initial starting position for PlayerD3DXVECTOR3 rocketPos = D3DXVECTOR3(300,300,0);cSprite theRocket(rocketPos,d3dMgr->getTheD3DDevice(),"Images\\player.png");theRocket.setTranslation(D3DXVECTOR2(10.0f,0.0f));// Initial starting position for RocketD3DXVECTOR3 enemyPos;/* initialize random seed: */srand ( (unsigned int)time(NULL) );/* generate random number of balloons */int numEnemy = (rand() % 5 + 1);for(int loop = 0; loop < numEnemy; loop++){enemyPos = D3DXVECTOR3((float)clientBounds.right/(loop+2),0,0);aEnemy.push_back(new cBalloon(enemyPos,d3dMgr->getTheD3DDevice(),"Images\\enemy.png"));aEnemy[loop]->setTranslation(D3DXVECTOR2(5.0f,0.0f));}Draw code// Game code goes hereballoonPos = D3DXVECTOR3(balloonTrans.x,balloonTrans.y,0);/*==============================================================| Update the postion of the balloons and check for collisions==============================================================*/for(iter = aBalloon.begin(); iter != aBalloon.end(); ++iter){(*iter)->update();// update balloonaballoonPos = (*iter)->getSpritePos();  // get the position of the current balloon/*==============================================================| Check for boundry collision and change balloon direction==============================================================*/if (aballoonPos.x>(clientBounds.right - 60) || aballoonPos.x < 2 ){(*iter)->setTranslation((*iter)->getTranslation()*(-1));}/*==============================================================| Check each balloon against each other for collisions==============================================================*/for(index = aBalloon.begin(); index != aBalloon.end(); ++index){if ((*iter)->collidedWith((*iter)->getBoundingRect(),(*index)->getBoundingRect())){// if a collision occurs change the direction of each balloon that has collidedOutputDebugString("Collision!!");(*iter)->setTranslation((*iter)->getTranslation()*(-1));(*index)->setTranslation((*index)->getTranslation()*(-1));}}}d3dMgr->beginRender();theBackbuffer = d3dMgr->getTheBackBuffer();d3dMgr->updateTheSurface(aSurface, theBackbuffer);d3dMgr->releaseTheBackbuffer(theBackbuffer);d3dxSRMgr->beginDraw();for(iter = aBalloon.begin(); iter != aBalloon.end(); ++iter){d3dxSRMgr->setTheTransform((*iter)->getSpriteTransformMatrix());  d3dxSRMgr->drawSprite((*iter)->getTexture(),NULL,NULL,NULL,0xFFFFFFFF);}d3dxSRMgr->endDraw();d3dMgr->endRender();
  This appears to only be the code for rendering your balloons. Can you post your entire render routine?   ;[source ="cpp"]/*=================main.cppMain entry point for the Card application=================*/#include "GameConstants.h"#include "GameResources.h"#include "cD3DManager.h"#include "cD3DXSpriteMgr.h"#include "cD3DXTexture.h"#include "cSprite.h"#include "cExplosion.h"#include "cXAudio.h"#include "cBalloon.h"using namespace std;HINSTANCE hInst; // global handle to hold the application instanceHWND wndHandle; // global variable to hold the window handle// Get a reference to the DirectX Managerstatic cD3DManager* d3dMgr = cD3DManager::getInstance();// Get a reference to the DirectX Sprite renderer Manager static cD3DXSpriteMgr* d3dxSRMgr = cD3DXSpriteMgr::getInstance();RECT clientBounds;const RECT playerBounds;TCHAR szTempOutput[30];bool gHit = false;D3DXVECTOR3 expPos;list<cExplosion*> gExplode;cXAudio gExplodeSound;D3DXVECTOR2 rocketTrans = D3DXVECTOR2(400,500);D3DXVECTOR2 enemyTrans1 = D3DXVECTOR2(100,100);D3DXVECTOR2 enemyTrans2 = D3DXVECTOR2(300,100);D3DXVECTOR2 enemyTrans3 = D3DXVECTOR2(500,100);D3DXVECTOR2 enemyTrans4 = D3DXVECTOR2(300,300);vector<cBalloon*> aEnemy;vector<cBalloon*>::const_iterator iterRO;vector<cBalloon*>::iterator iter;vector<cBalloon*>::iterator index;/*==================================================================* LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,* LPARAM lParam)* The window procedure==================================================================*/LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){// Check any available messages from the queueswitch (message){case WM_KEYDOWN:{//Keep player inside the screen.if(rocketTrans.x <= 0){rocketTrans.x = 0;}if(rocketTrans.x >= 650){rocketTrans.x = 650;}//keys for player movement.if (wParam == VK_LEFT){rocketTrans.x -= 10.0f;return 0;}if (wParam == VK_RIGHT){rocketTrans.x += 10.0f;return 0;}if (wParam == VK_UP){rocketTrans.y -= 10.0f;return 0;}if (wParam == VK_DOWN){rocketTrans.y += 10.0f;return 0;}return 0;}case WM_LBUTTONDOWN:{POINT mouseXY;mouseXY.x = LOWORD(lParam);mouseXY.y = HIWORD(lParam);expPos = D3DXVECTOR3((float)mouseXY.x,(float)mouseXY.y, 0.0f);gExplode.push_back(new cExplosion(expPos,d3dMgr->getTheD3DDevice(),"Images\\explosion.png"));gExplodeSound.playSound(L"Sounds\\explosion.wav",false);StringCchPrintf(szTempOutput, STRSAFE_MAX_CCH, TEXT("Mouse: lLastX=%d lLastY=%d\r\n"), LOWORD(lParam), HIWORD(lParam));OutputDebugString(szTempOutput);return 0;}case WM_CLOSE:{// Exit the GamePostQuitMessage(0); return 0;}case WM_DESTROY:{PostQuitMessage(0);return 0;}}// Always return the message to the default window// procedure for further processingreturn DefWindowProc(hWnd, message, wParam, lParam);}/*==================================================================* bool initWindow( HINSTANCE hInstance )* initWindow registers the window class for the application, creates the window==================================================================*/bool initWindow( HINSTANCE hInstance ){WNDCLASSEX wcex;// Fill in the WNDCLASSEX structure. This describes how the window// will look to the systemwcex.cbSize = sizeof(WNDCLASSEX); // the size of the structurewcex.style = CS_HREDRAW | CS_VREDRAW; // the class stylewcex.lpfnWndProc = (WNDPROC)WndProc; // the window procedure callbackwcex.cbClsExtra = 0; // extra bytes to allocate for this classwcex.cbWndExtra = 0; // extra bytes to allocate for this instancewcex.hInstance = hInstance; // handle to the application instancewcex.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_MyWindowIcon)); // icon to associate with the applicationwcex.hCursor = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_GUNSIGHT));// the default cursorwcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); // the background colorwcex.lpszMenuName = NULL; // the resource name for the menuwcex.lpszClassName = "Balloons"; // the class name being createdwcex.hIconSm = LoadIcon(hInstance,"Balloon.ico"); // the handle to the small iconRegisterClassEx(&wcex);// Create the windowwndHandle = CreateWindow("Balloons",// the window class to use "Balloon Burst",// the title bar textWS_OVERLAPPEDWINDOW,// the window styleCW_USEDEFAULT, // the starting x coordinateCW_USEDEFAULT, // the starting y coordinate800, // the pixel width of the window600, // the pixel height of the windowNULL, // the parent window; NULL for desktopNULL, // the menu for the application; NULL for nonehInstance, // the handle to the application instanceNULL); // no values passed to the window// Make sure that the window handle that is created is validif (!wndHandle)return false;// Display the window on the screenShowWindow(wndHandle, SW_SHOW);UpdateWindow(wndHandle);return true;}/*==================================================================// This is winmain, the main entry point for Windows applications==================================================================*/int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ){// Initialize the windowif ( !initWindow( hInstance ) )return false;// called after creating the windowif ( !d3dMgr->initD3DManager(wndHandle) )return false;if ( !d3dxSRMgr->initD3DXSpriteMgr(d3dMgr->getTheD3DDevice()))return false;// Grab the frequency of the high def timer__int64 freq = 0;// measured in counts per second;QueryPerformanceFrequency((LARGE_INTEGER*)&freq);float sPC = 1.0f / (float)freq;// number of seconds per count__int64 currentTime = 0;// current time measured in counts per second;__int64 previousTime = 0;// previous time measured in counts per second;float numFrames   = 0.0f;// Used to hold the number of framesfloat timeElapsed = 0.0f;// cumulative elapsed timeGetClientRect(wndHandle,&clientBounds);float fpsRate = 1.0f/25.0f;LPDIRECT3DSURFACE9 aSurface;// the Direct3D surfaceLPDIRECT3DSURFACE9 theBackbuffer = NULL;  // This will hold the back bufferMSG msg;ZeroMemory( &msg, sizeof( msg ) );// Initial starting position for PlayerD3DXVECTOR3 rocketPos = D3DXVECTOR3(300,300,0);cSprite theRocket(rocketPos,d3dMgr->getTheD3DDevice(),"Images\\player.png");theRocket.setTranslation(D3DXVECTOR2(10.0f,0.0f));// Initial starting position for RocketD3DXVECTOR3 enemyPos;/* initialize random seed: */srand ( (unsigned int)time(NULL) );/* generate random number of balloons */int numEnemy = (rand() % 5 + 1);for(int loop = 0; loop < numEnemy; loop++){enemyPos = D3DXVECTOR3((float)clientBounds.right/(loop+2),0,0);aEnemy.push_back(new cBalloon(enemyPos,d3dMgr->getTheD3DDevice(),"Images\\enemy.png"));aEnemy[loop]->setTranslation(D3DXVECTOR2(5.0f,0.0f));}// Initial starting position for Enemies D3DXVECTOR3 enemyPos1 = D3DXVECTOR3(300,300,0);cSprite theEnemy1(enemyPos1,d3dMgr->getTheD3DDevice(),"Images\\enemy.png");theEnemy1.setTranslation(D3DXVECTOR2(5.0f,0.0f));// Create the background surfaceaSurface = d3dMgr->getD3DSurfaceFromFile("Images\\space.png");D3DXVECTOR3 aEnemyPos;while( msg.message!=WM_QUIT ){// Check the message queueif (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) ){TranslateMessage( &msg );DispatchMessage( &msg );}else{// Game code goes hererocketPos = D3DXVECTOR3(rocketTrans.x,rocketTrans.y,0);theRocket.setSpritePos(rocketPos);enemyPos1 = D3DXVECTOR3(enemyTrans1.x,enemyTrans1.y,0);theEnemy1.setSpritePos(enemyPos1);QueryPerformanceCounter((LARGE_INTEGER*)&currentTime);float dt = (currentTime - previousTime)*sPC;// Accumulate how much time has passed.timeElapsed += dt;if(timeElapsed > fpsRate){for(iter = aEnemy.begin(); iter != aEnemy.end(); ++iter){(*iter)->update();aEnemyPos = (*iter)->getSpritePos();  if (aEnemyPos.x>(clientBounds.right - 60) || aEnemyPos.x < 2 ){(*iter)->setTranslation((*iter)->getTranslation()*(-1));}for(index = aEnemy.begin(); index != aEnemy.end(); ++index){if ((*iter)->collidedWith((*iter)->getBoundingRect(),(*index)->getBoundingRect())){OutputDebugString("Collision!!");(*iter)->setTranslation((*iter)->getTranslation()*(-1));(*index)->setTranslation((*index)->getTranslation()*(-1));}}}rocketPos = D3DXVECTOR3(rocketTrans.x,rocketTrans.y,0);theRocket.setSpritePos(rocketPos);d3dMgr->beginRender();theBackbuffer = d3dMgr->getTheBackBuffer();d3dMgr->updateTheSurface(aSurface, theBackbuffer);d3dMgr->releaseTheBackbuffer(theBackbuffer);d3dxSRMgr->beginDraw();//d3dxSRMgr->drawSprite(theEnemy1.getTexture(),NULL,NULL,&theEnemy1.getSpritePos(),0xFFFFFFFF);for(iter = aEnemy.begin(); iter != aEnemy.end(); ++iter){d3dxSRMgr->setTheTransform((*iter)->getSpriteTransformMatrix());  d3dxSRMgr->drawSprite((*iter)->getTexture(),NULL,NULL,NULL,0xFFFFFFFF);}d3dxSRMgr->drawSprite(theRocket.getTexture(),NULL,NULL,&theRocket.getSpritePos(),0xFFFFFFFF);d3dxSRMgr->endDraw();d3dMgr->endRender();}}}d3dxSRMgr->cleanUp();d3dMgr->clean();return (int) msg.wParam;}Sorry about that. Here is a copy of my entire main class. This is where all my game code is.   