Sign in to follow this  
fragbear

Drawing A LOT of sprites? (Directx9)

Recommended Posts

Hey. I've been having some really hard time with drawing large amount of sprites.
Basically what I want to do is draw lots of sprites, so many that giving them their position etc. like I did before is not possible.

This is how I did it before:
void render_frame(void)
{
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(128, 64, 0), 1.0f, 0);
d3ddev->BeginScene();

d3dspr->Begin(D3DXSPRITE_ALPHABLEND);

D3DXVECTOR3 center(1280.0f, 1280.0f, 0.0f);
D3DXVECTOR3 position(1150.0f, 200.0f, 0.0f);
d3dsce->Draw(mysprite, NULL, ¢er, &position, D3DCOLOR_ARGB(255, 128, 128, 128));

d3dspr->End();

d3ddev->EndScene();
d3ddev->Present(NULL, NULL, NULL, NULL);

return;
}




But now I have atleast 100 sprites, so obviously I'm not going to do that now.

I've been trying to make an array of D3DXVECTOR3 aswell as of the sprites, and then assign the values for "position" and "center" in a for-loop. But the problem is that making something like this: D3DXVECTOR3 center[i] = (floatx, floaty, floatz) gives an error.

Do you have any idea how to make that work, or can I even do it? And if I can't, then do you know any alternative way(s)?

So in a nutshell: I need to draw a lot of sprites. How do I do it?


Thanks in advance.

Share this post


Link to post
Share on other sites
I would create a struct like this:

struct Location
{
D3DXVECTOR3 center;
D3DXVECTOR3 position;
}



Then you create an array of locations:

Location locs[100];
locs[0].center = D3DXVECTOR3(1.0f,1.0f,1.0f);
locs[0].position = D3DXVECTOR3(2.0f,2.0f,1.0f);
locs[1].center = D3DXVECTOR3(44.0f,44.0f,44.0f);
locs[1].position = D3DXVECTOR3(2.0f,2.0f,1.0f);
...
...
...



And then you create a for loop:

for(int x = 0; x < 100; x++)
{
d3dsce->Draw(mysprite, NULL, &locs[x].center, &locs[x].position, D3DCOLOR_ARGB(255, 128, 128, 128));
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this