Sign in to follow this  
andyb716

ID3DXSprite?

Recommended Posts

Can anyone tell how to use sprites in Direct3D. Do you just make an instance of it and set it to use a bitmap for the texture. And how do you move it around the screen. I looked at the msdn documentation and I don't know how to implement these functions. I'm a real newbie to this so any comments would help. Thanks to everyone.

Share this post


Link to post
Share on other sites
I read in the msdn documentation that the Draw method has a parameter for a texture. Do I have to call this in between the Begin and End Method? It has a position also that is a D3DXVECTOR3, do I update the vector every time I want it to move?

Share this post


Link to post
Share on other sites
It's very easy. You do it like this:
// Load-time
(1) Create the ID3DXSprite object, using the D3DXCreateSprite factory function.

(2) Load your textures

// Run-time
(1) Call ID3DXSprite::Begin()

(2) For each texture you want to render
(a) - Build and apply the translation matrix for a world-space translation
or
- Build the position vector for a screen-space translation
(b) Call ID3DXSprite::Draw()

(3) Call ID3DXSprite::End()

Share this post


Link to post
Share on other sites
Don't think of D3DXSprite as an object or anything related to an instance of a single sprite. That's incorrect.

Instead, just view it as some extra code packaged into a single interface. You create a D3DXSprite to pull that code into memory, like loading a DLL; call through the ID3DXSprite interface to use the functions provided by that DLL; and then release the interface, like unloading a DLL. If you had a DLL providing behaviour for a specific enemy in your game, you wouldn't load it once per enemy...

Share this post


Link to post
Share on other sites
Quote:
Original post by circlesoft
It's very easy. You do it like this:
** Code Snippet **


Déjà Vu?

Andy: you have to load the texture into an textureobject, and then use a single instance of ID3DXSprite to draw all your textures.

Share this post


Link to post
Share on other sites
Quote:
Original post by Pipo DeClown
Quote:
Original post by circlesoft
It's very easy. You do it like this:
** Code Snippet **


Déjà Vu?

[grin]
That's part of our (Dustin and me) proprietary, patent-pending technologies: Templated answers to extremely frequently asked questions, or TateFaq for short.

Share this post


Link to post
Share on other sites
Quote:
Original post by Coder
[grin]
That's part of our (Dustin and me) proprietary, patent-pending technologies: Templated answers to extremely frequently asked questions, or TateFaq for short.

Hehe.. I don't understand what you just said there (was that a joke?), but can I join in? Do you have more like those snippets?

Share this post


Link to post
Share on other sites
Quote:
Original post by andyb716
Alright I got something to display on the screen. And what do you mean use a single instance, just use the draw() function for every texture I have?


Yes - as others say the sprite object just provides a set of interfaces so only one is needed and in fact you get better performance using just one. I have a page on using DX sprites you might be interested in here:
Sprites

Share this post


Link to post
Share on other sites
So from reading your tutorial, say I have a texture which is 128*128. If I want this texture to work as a banner across my screen (and I'm assuming sprites measure in pixels not logical coords), is there anyway for me to resize it to say 1024 width by 64 height, or does the interface require the texture to be rendered as a squared texture?

Thanks,

Permafried-

Share this post


Link to post
Share on other sites
No it does not need to be square but each dimension should be a power of 2 (video card limitation). To stretch it you could scale it - look in my advanced notes - using the SetTransform function. How good it will look though I am not sure.

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