Jump to content

  • Log In with Google      Sign In   
  • Create Account


Color key'ing automatically and... sprite creating lines?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 MarlboroKing   Members   -  Reputation: 192

Like
0Likes
Like

Posted 10 February 2012 - 02:41 PM

Fixed - It would help so much more if I actually friggin' cleared the screen...
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).

Posted Image
(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;
}


Sponsor:

#2 Retsu90   Members   -  Reputation: 208

Like
1Likes
Like

Posted 12 February 2012 - 07:35 AM

1) The IDirect3DSurface9::Clear is a strange problem... Be sure to call it before to render everything and in every frame (put it on your DBeginScene) and call it for every surface that you use.
2) There isn't a way to determinate what is the key color. Some images has in their header the color that will be bypassed, other images simply set that color to 0% of alpha. I'm working on a 2D engine too, and I advise you to set on every texture the background color 0xFF00FF (light purple) and uses key color 0xFFFF00FF as param in D3DXCreateTextureFromFileEx.

Good luck!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS