Jump to content
  • Advertisement
Sign in to follow this  
fragbear

Drawing A LOT of sprites? (Directx9)

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

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 = (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
Advertisement
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
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!