When I run the program, all the sprites are in the correct position, however when I press a button to move the paddle it stays in the same place. I know that the input is working because I tested it with system beeps, and I know that the position of the sprite is changing because I had the x and y coordinates sent to a file as I pressed the button. Im not sure why the texture stays in the same place. Here's the code:
I also uploaded the entire project incase anyone wanted a closer look
//WinMain.cpp
Object Ball;
Ball.setTexture( g.LoadTexture( "Resources/Ball.png" ) );
Ball.setImageInfo( "Resources/Ball.png" );
Ball.setPosition( ( ( WindowWidth / 2 ) - Ball.getImageInfo().Width ), ( ( WindowHeight / 2 ) - Ball.getImageInfo().Height ) );
Object LeftPaddle;
LeftPaddle.setTexture( g.LoadTexture( "Resources/LeftPaddle.png" ) );
LeftPaddle.setImageInfo( "Resources/LeftPaddle.png" );
LeftPaddle.setPosition( 0, ( ( WindowHeight / 2 ) - LeftPaddle.getImageInfo().Height ) );
Object RightPaddle;
RightPaddle.setTexture( g.LoadTexture( "Resources/RightPaddle.png" ) );
RightPaddle.setImageInfo( "Resources/RightPaddle.png " );
RightPaddle.setPosition( ( WindowWidth - RightPaddle.getImageInfo().Width ), ( WindowHeight / 2 ) - RightPaddle.getImageInfo().Height );
g.getObjectManager().AddObject( Ball );
g.getObjectManager().AddObject( LeftPaddle );
g.getObjectManager().AddObject( RightPaddle );
Input i;
i.InitInput( window );
while ( GameOver != true )
{
if ( PeekMessage( &message, NULL, 0, 0, PM_REMOVE ) )
{
TranslateMessage( &message );
DispatchMessage( &message );
}
i.RefreshInput();
if ( i.KeyPressed( DIK_ESCAPE ) )
{
GameOver = true;
}
if ( i.KeyPressed( DIK_UP ) )
{
LeftPaddle.Move( 0.0f, -0.5f );
}
if ( i.KeyPressed( DIK_DOWN ) )
{
LeftPaddle.Move( 0.0f, 0.5f );
}
g.UpdateGraphics();
}
//ObjectManager.h
#ifndef OBJECTMANAGER_H
#define OBJECTMANAGER_H
#include "Object.h"
#include <list>
#include <d3dx9.h>
class ObjectManager
{
public:
//ObjectManager() {}
//~ObjectManager() {}
void AddObject( Object &object );
void ReleaseTextures();
void UpdateObjectManager( LPD3DXSPRITE &sprite );
private:
std::list<Object> Objects;
std::list<Object>::iterator Iter;
};
#endif OBJECTMANAGER_H
//ObjectManager.cpp
#include "ObjectManager.h"
#include "Globals.h"
void ObjectManager::AddObject( Object &object )
{
Objects.push_back( object );
}
void ObjectManager::ReleaseTextures()
{
Iter = Objects.begin();
while ( Iter != Objects.end() )
{
RELEASE( Iter -> getTexture() );
Iter++;
}
}
void ObjectManager::UpdateObjectManager( LPD3DXSPRITE &sprite )
{
Iter = Objects.begin();
while ( Iter != Objects.end() )
{
sprite -> Draw( Iter -> getTexture(), NULL, NULL, &Iter -> getPosition(), White );
Iter++;
}
}
//Graphics.h
#ifndef GRAPHICS_H
#define GRAPHICS_H
#include "DxManager.h"
#include "ObjectManager.h"
#include <d3dx9.h>
#include <string>
class Graphics
{
public:
bool InitGraphics( HWND &window );
void StartScene();
void Render();
void EndScene();
void UpdateGraphics();
void ReleaseTextures();
LPDIRECT3DTEXTURE9 LoadTexture( std::string file );
DxManager &getD3DManager() { return this -> D3DManager; }
ObjectManager &getObjectManager() { return this -> ObjManager; }
HWND &getWindow() { return this -> Window; }
private:
HWND Window;
DxManager D3DManager;
ObjectManager ObjManager;
};
#endif GRAPHICS_H
//Graphics.cpp
#include "Graphics.h"
#include "Globals.h"
bool Graphics::InitGraphics( HWND &window )
{
this -> Window = window;
if( !D3DManager.InitD3D( window ) )
{
GameOver = true;
MessageBox( window, "Error initializing DirectX9", "Error", MB_OK );
return false;
}
return true;
}
void Graphics::StartScene()
{
D3DManager.getDirect3DDevice() -> Clear( 0, NULL, D3DCLEAR_TARGET, Black, 0.0f, 0 );
D3DManager.getDirect3DDevice() -> BeginScene();
D3DManager.getSpriteObject() -> Begin( D3DXSPRITE_ALPHABLEND );
}
void Graphics::Render()
{
ObjManager.UpdateObjectManager( D3DManager.getSpriteObject() );
}
void Graphics::EndScene()
{
D3DManager.getSpriteObject() -> End();
D3DManager.getDirect3DDevice() -> EndScene();
D3DManager.getDirect3DDevice() -> Present( NULL, NULL, NULL, NULL );
}
void Graphics::UpdateGraphics()
{
StartScene();
Render();
EndScene();
}
void Graphics::ReleaseTextures()
{
ObjManager.ReleaseTextures();
}
LPDIRECT3DTEXTURE9 Graphics::LoadTexture( std::string file )
{
LPDIRECT3DTEXTURE9 texture = NULL;
D3DXIMAGE_INFO info;
D3DXGetImageInfoFromFile( file.c_str(), &info );
HRESULT hr = D3DXCreateTextureFromFileEx(
D3DManager.getDirect3DDevice(),
file.c_str(),
info.Width, info.Height,
1,
D3DPOOL_DEFAULT,
D3DFMT_UNKNOWN,
D3DPOOL_DEFAULT,
D3DX_DEFAULT,
D3DX_DEFAULT,
Transparent,
&info,
NULL,
&texture );
return texture;
}