Jump to content
  • Advertisement
Sign in to follow this  

DirectX 2d game

This topic is 1821 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, after some time trying again to make something with directX 9, and what I chose is 2D game. For now making only basics of engine, which will help to me make a game. And writing here because need help about drawing objects. Now use LPD3DXSPRITE for painting. But get some "flickering" of moving object. Maybe anybody could say why I get it? Or maybe suggest better way to draw 2D.


Painting function:

void Sprite::Render( Texture2D texture, TinyEngine::Rectangle rectangle )
D3DXVECTOR3 vCenter( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 vPosition( rectangle.X(), rectangle.Y(), 0.0f );
RECT rect;
rect.left =0;
rect.right = 48;
_sprite->Draw( texture.Texture(),
D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,0.80f) );

Texture loading function:

_fileName = fileName;
_width = width;
_height = height;
Vertex g_quadVertices[] =
{-1.0f, 1.0f, 0.0f,  0.0f,0.0f },
{ 1.0f, 1.0f, 0.0f,  1.0f,0.0f },
{-1.0f,-1.0f, 0.0f,  0.0f,1.0f },
{ 1.0f,-1.0f, 0.0f,  1.0f,1.0f }
D3DXIMAGE_INFO d3dxImageInfo;
fileName, //"Data//Images//first.png",
g_dxManager.GetDevice()->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
g_dxManager.GetDevice()->CreateVertexBuffer( 4*sizeof(Vertex), D3DUSAGE_WRITEONLY, 
&_vertexBuffer, NULL );
void *pVertices = NULL;
_vertexBuffer->Lock( 0, sizeof(g_quadVertices), (void**)&pVertices, 0);
memcpy( pVertices, g_quadVertices, sizeof(g_quadVertices));

And adding project exe to see what flickering I get smile.png


Share this post

Link to post
Share on other sites

I'd guess that the window client size doesn't match your backbuffer size. The actual client size is 784x602. From the actual window size (800x640) it looks like you tried for 800x600?


If it is so, your problem is nothing with DirectX but with your Win32. Try setting a RECT to your wanted client size, call AdjustWindowRect(Ex) on it and use the result RECT for your CreateWindow(Ex) call.



Also, your message loop seems borked. When I close the game window the program crashes.

Share this post

Link to post
Share on other sites

Somehow it works, but now want to know how properly to do it. First I now use


and later I use

_parameters.BackBufferFormat =  D3DFMT_X8R8G8B8;
_parameters.BackBufferWidth = SCREEN_WIDTH;
_parameters.BackBufferHeight = SCREEN_HEIGHT;

What values I need set if I want see 800x600 client size?

Because now Rect make very big window in both screens




K, founded how to fix it and get what I want. Thanks for help :)

Edited by Plutonium

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!