Jump to content
  • Advertisement
Sign in to follow this  
hkslphie

Need help with 2D Sprites

This topic is 4382 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 created a texture and a LPD3DXSPRITE sprite to display it on the screen, but I do not see anything. I know everything else was working fine, except this block of code I just added to play around with: if (FAILED( D3DXCreateTextureFromFile(pd3dDevice, "shooter.bmp ", &planeTexture))) MessageBox(wndHandle, "yea", "whatever", MB_OK); if (FAILED( D3DXCreateSprite(pd3dDevice, &player_sprite))) MessageBox(wndHandle, "yea", "failed to create sprite", MB_OK); ..... .... player_sprite->Begin(D3DXSPRITE_ALPHABLEND); player_sprite->Draw(planeTexture, NULL, NULL, NULL, 0xFFFFFFFF); player_sprite->End(); I had a position vector for the draw function paramter, but also didn't see anything. Am I forgetting something? The tutorial I found on this subject didn't mention anything about acquring the back buffer. So is this drawing straight to the front buffer? Also, which way is more efficient: using texture interface and sprite object, or using surfaces to store bitmap/tileset then draw sprites to the back buffer by using strectchrect and presenting it? I know that by using the sprite interface, we can do matrix transformation, rotation, and scaling, but if my sprites do not need these operations, is it faster to just use the latter method? Any help with the question(s) is appreciated. Thank you in advance.

Share this post


Link to post
Share on other sites
Advertisement
When using ID3DXSprite you still need to call BeginScene, EndScene and Present. ID3DXSprite draws to the backbuffer, as does any other DX drawing method. Calling Present then presents that backbuffer as the frontbuffer.
Other than that part missing, I can't find anything wrong with your code. You could try disabling the Z-buffer if you're not using it, or make sure you're clearing it if you plan on using it.

I'd expect ID3DXSprite to outperform StretchRect. It also allows for more complex effects (color modulations, alphablending, transformations), as well as allowing for good batching. ID3DXSprite is definatly preferable over StretchRect.

Hope this helps.

Share this post


Link to post
Share on other sites
Yea, got it to work by adding beginscene, endscene and present. Thanks.

Now, I'm trying to find out how to set the area around the sprite in the same bitmap block transparent. Is there a way?

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!