Jump to content
  • Advertisement
Sign in to follow this  
jonyfries

DirectX Sprite Problem

This topic is 4307 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

I'm attempting to cover the basics of C++ game programming right now (having a spattering of non-game experiance in QBasic, Visual Basic, and C++) So I am running through a book on basic 2D and 3D DirectX programming using VC++. So, I copied is code off the CD and tried to run it and I get the following errors: error C2065: 'D3DXSPRITE_ALPHABLEND' : undeclared identifier error C2660: 'ID3DXSprite::Draw' : function does not take 5 arguments The code that generates the errors is as follows: LPD3DXSPRITE sprite_handler; sprite_handler->Begin(D3DXSPRITE_ALPHABLEND); sprite_handler->Draw( caveman_image, &srcRect, NULL, &position, D3DCOLOR_XRGB(255,255,255)); Thinking that perhaps DirectX had changed its functions and/or flags I checked out MSDN and what I found said that this should work. Which left me quite confused. I recieve no other errors, which means, I believe, that all of the proper #include calls are there. I'm using VC++ 2003 and I downloaded the aug2006 update to the DirectX SDK yesterday.

Share this post


Link to post
Share on other sites
Advertisement
This is old advice, and may not even be good anymore, but if you don't mind digging thru archived documentation on msdn, I recommend starting your gaming werk with DirectDraw (from DirectX7). It's many many times simpler than Direct3d (at least, to my memory), and isn't a bad place to start.

Also, I've never worked with Direct3D (DirectDraw and OpenGL here), so I'm a touch biased <3

Sorry I couldn't be of more help. Hope someone reads this thread who can answer your direct question =) good luck.

Share this post


Link to post
Share on other sites
Are you including d3dx9.h as opposed to 8? Bit weird if so because I, like you, have just checked MSDN and DirectX 9 does indeed have D3DXSPRITE_ALPHABLEND and Draw does indeed take five parameters.

Have to disagree with serratemplar about DirectDraw. Personally I think Direct3D 8 onwards are actually easier to set up than DirectDraw and with ID3DXSprite, it should be almost easy to use for 2D stuff.

Plus you get loads of benefits like hardware alpha blending, scaling, rotation, vertex colouring (whatever the proper name for that is) and DirectDraw is now deprecated so hardware support for it is on its way out and I believe the interface has been dumped entirely from DirectX 10.

You'll end up having to relearn most stuff when you do switch to Direct3D so why put yourself through it?

Also, if you have a fast enough internet connection, upgrade Visual Studio to 2005. I don't know if it will affect this issue, but there is little reason not to.

Share this post


Link to post
Share on other sites
Personally I'd be more inclined to find out why this isn't working first. DirectX 9 ships with all the older interfaces anyway so I don't think getting an older SDK would help.

Could you paste the complete code in [ source ][ /source ] tags (without the spaces)? Perhaps someone here will be able to help.

Share this post


Link to post
Share on other sites
//the main game loop
void Game_Run(HWND hwnd)
{
//make sure the Direct3D device is valid
if (d3ddev == NULL)
return;


//after short delay, ready for next frame?
//this keeps the game running at a steady frame rate
if (GetTickCount() - start >= 30)
{
//reset timing
start = GetTickCount();

//move the sprite
caveman.x += caveman.movex;
caveman.y += caveman.movey;

//"warp" the sprite at screen edges
if (caveman.x > SCREEN_WIDTH - caveman.width)
caveman.x = 0;
if (caveman.x < 0)
caveman.x = SCREEN_WIDTH - caveman.width;

//has animation delay reached threshold?
if (++caveman.animcount > caveman.animdelay)
{
//reset counter
caveman.animcount = 0;

//animate the sprite
if (++caveman.curframe > caveman.lastframe)
caveman.curframe = 1;
}
}

//start rendering
if (d3ddev->BeginScene())
{
//erase the entire background
d3ddev->StretchRect(back, NULL, backbuffer, NULL, D3DTEXF_NONE);

//start sprite handler
sprite_handler->Begin(D3DXSPRITE_ALPHABLEND);

//create vector to update sprite position
D3DXVECTOR3 position((float)caveman.x, (float)caveman.y, 0);

//configure the rect for the source tile
RECT srcRect;
int columns = 8;
srcRect.left = (caveman.curframe % columns) * caveman.width;
srcRect.top = (caveman.curframe / columns) * caveman.height;
srcRect.right = srcRect.left + caveman.width;
srcRect.bottom = srcRect.top + caveman.height;

//draw the sprite
sprite_handler->Draw(
caveman_image,
&srcRect,
NULL,
&position,
D3DCOLOR_XRGB(255,255,255));

//stop drawing
sprite_handler->End();

//stop rendering
d3ddev->EndScene();
}

//display the back buffer on the screen
d3ddev->Present(NULL, NULL, NULL, NULL);

//check for escape key (to exit program)
if (KEY_DOWN(VK_ESCAPE))
PostMessage(hwnd, WM_DESTROY, 0, 0);

}


This is the function that both errors occur in, the #include are in a seperate header file. (Which is, of course, included in this .cpp file.) The program as a whole doesn't really do much, just causes a little animated caveman to run across the screen. Well... thats what its supposed to do anyway.

Share this post


Link to post
Share on other sites
I think I know what book your using Beginning Game Programming right?

Anyway I had a similar problem, but it had to do with outdated files that the author was using in the code. Do you have a file dxgraphics.cpp and dxgraphics.h. If not you should see if you can find the books homepage for updated code. Once I updated all the code everything worked fine. Here is what I ended up with in a game I made:


void PlayerControl::Draw()
{
RECT srcRect;
if(!attack)
{

srcRect.left = (blueknight.curframe % WALKCOLUMNS) *blueknight.width;
srcRect.top = (blueknight.curframe/WALKCOLUMNS) * blueknight.height;
srcRect.right = (srcRect.left + blueknight.width);
srcRect.bottom = (srcRect.top + blueknight.height);

position.x = (float)blueknight.x;
position.y = (float)blueknight.y;
position.z = 0.0f;

sprite_handler->Draw(
blue_knight_walk_image,
&srcRect,
NULL,
&position,
D3DCOLOR_XRGB(255,255,255));
}




Don't rely to much on that book though because I have not been able to get any of the programs I made to run on anyother computers. Something is up with the D3D code.

Share this post


Link to post
Share on other sites
I have had a few problems with the code as well, but I've always been able to fix it pretty easily by wandering around MSDN. If I'm not mistaken it was writen using VC++ 6.0 which I figure is why theres a problem. Considering the books copyright is 2005 I do find it a bit strange that it wasn't written with VC++ 2003.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!