Skip to main content
gamedev.net
🔒 Locked

Sprites?

Started by CaptCanada Mar 11, 2004 at 3:59 PM 0 replies 500+ views
Original Post
CaptCanada
CaptCanada
Hi all I am writing an arcade shooter and would like to know if there are any tutorials on the subject of loading and displaying game sprites? Do I need to use D3DXCreateSprite? Right now, I just have a surface that displays the background image. Do I need to create another surface for my sprite(s) as well as an additional backbuffer? Do I use D3DXCreateTextureFromFileEx? Thanks for any info regarding this matter.
Better to try and fail than to fail by not trying.
grasshopa55
grasshopa55
D3DXCreateSprite actually doesn't create a sprite at all. What it does do is create an instance of the ID3DXSprite object. This object lets you easily draw any texture to the screen with minimal effort.

-- begin mini-tutorial --
A quick look at the DirectX 9 Documentation shows that ID3DXSprite has 11 methods, but to get started, all you really need are the following:

Begin - Sets up the various render states and prepares the device for drawing.
Draw - Draws your textured sprite to the screen.
End - Resets the various render states.

For now, concentrate on the Draw function.

You'll need to get your sprite loaded onto a texture before you can use the Draw() method. Take a quick look at D3DXCreateTextureFromFile(). This simple method will load any supported image (png, jpeg, bmp, etc..) onto a LPDIRECT3DTEXTURE9 object.

Once you have the texture loaded, you are ready to draw your sprite. In your rendering loop, simply add the Draw() call between your BeginScene(), EndScene() calls:


D3DXVECTOR2 vecSpritePosition( 0, 0 );
lpDevice->BeginScene();

// created with D3DXCreateSprite()

lpSprite->Begin();

// draw the sprite at the origin

lpSprite->Draw( &lpSpriteTexture, NULL, NULL, &vecSpritePosition, NULL );

lpSprite->End();
lpDevice->EndScene();


-- end mini-tutorial --

That should be enough to get you started. There are plenty of other full tutorials here on gamedev, so take a look around

-----------------------------
kevin@mayday-anime.com
http://www.mayday-anime.com

[edited by - grasshopa55 on March 11, 2004 8:38:07 PM]
-----------------------------kevin@mayday-anime.comhttp://www.mayday-anime.com

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.