DGetD3DDevice()->Clear( NULL, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 1.0f, NULL );[
So, I was testing my engine last night and everything seemed to be going smoothly until I up'd my sprite's speed. Once its speed is greater than 2.0f, the sprite kinda just creates lines as it goes (see screenshot).
(Note; it only happens when moving up because I only change its -Y speed to cause this problem)
I did test another sprite, using a different color key I specified in D3DXCreateTextureFromFileEx(), and it basically
copied the entire image as I moved - could my original problem (the sprite I'm using with the correct color key) be because of
the color key? I don't entirly see how...
As for my second problem, I see that Windows 7 Windows Photo Viewer automatically determines what RGB to use for the color key - how can I do the same? Should I just pick a pixel at 1,1 and extract its value? (Not entirely sure how to do that, but if that's the best solution, I'll just swing by my good ol' friend Google's house)
Here's the important part of my code:
Update/Render loop
DRESULT OnUpdate( LPVOID )
{
//Note; this can be cleaner but atm, it's just a test.
DGetInput()->Update();
DSprite* p = DFindSprite( 1 );
D3DXVECTOR3 fPos = p->GetPosition();
int nImgWidth = p->GetImage()->GetWidth();
int nImgHeight = p->GetImage()->GetHeight();
if( DGetInput()->IsKeyDown( DIK_W ) && !DGetInput()->IsKeyDown( DIK_S ) )
{
if( fPos.y > 0 )
{
fPos.y -= 5.0f;
p->SetPosition( fPos );
}
}
if( DGetInput()->IsKeyDown( DIK_S ) && !DGetInput()->IsKeyDown( DIK_W ) )
{
float fEdge = ((float)nImgWidth + fPos.y);
if( fEdge < DGetWindowHeight() )
{
fPos.y += 3.0f;
p->SetPosition( fPos );
}
}
if( DGetInput()->IsKeyDown( DIK_A ) && !DGetInput()->IsKeyDown( DIK_D ) )
{
if( fPos.x > 0 )
{
fPos.x -= 3.0f;
p->SetPosition( fPos );
}
}
if( DGetInput()->IsKeyDown( DIK_D ) && !DGetInput()->IsKeyDown( DIK_A ) )
{
float fEdge = ((float)nImgWidth + fPos.x );
if( fEdge < DGetWindowWidth() )
{
fPos.x += 3.0f;
p->SetPosition( fPos );
}
}
return D_OK;
}
DRESULT OnRender( LPVOID )
{
DSprite* pSprite = DFindSprite( 1 );
DBeginScene();
DSpriteBeginDraw( NULL );
D3DXVECTOR3 p = pSprite->GetPosition();
DGetD3DSprite()->Draw( pSprite->GetImage()->GetTexture(),
NULL, NULL, &p, 0xFFFFFFFF );
DSpriteEndDraw();
DEndScene();
DPresentScene();
return D_OK;
}
DImageLoad
bool DImage::Load( const char* szFilename, int nID )
{
strcpy_s( m_szFilename, szFilename );
HRESULT hRet = D3DXGetImageInfoFromFile( szFilename, &m_Info );
if( FAILED( hRet ) )
{
DWriteLastDxError( hRet );
return false;
}
hRet = D3DXCreateTextureFromFileEx( DGetMain()->GetD3DDeviceCOM(),
szFilename, m_Info.Width, m_Info.Height, 1, D3DPOOL_DEFAULT,
D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
0x70C0A0, &m_Info, NULL, &m_pTex );
if( FAILED( hRet ) )
{
DDebugPrint( "Failed to create texture '%s'.\n", szFilename );
DWriteLastDxError( hRet );
return false;
}
m_nID = nID;
return true;
}