Archived

This topic is now archived and is closed to further replies.

2D in DirectX Graphics

This topic is 5506 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 am working on a base class for objects in a 2D game using DirectX Graphics. I have created a texture management class, since all instances of a particular object will use the same textures. However, I am puzzled over the best way to handle the vertex buffers. Based upon the position of each instance of an object, a different set of vertices will be needed. Should I make the vertex buffer a member of the object class or should I have a seperate manager that maintains the vertices for one type of object and translate it to account for position?

Share this post


Link to post
Share on other sites
Did I ask a dumb question? Maybe I was too verbose:

Should each instance of an onscreen object class have its own Vertex Buffer?

or should they each have a pointer to the same Vertex Buffer and apply a transfer based on position?

Share this post


Link to post
Share on other sites
I''d recommend using one vertex buffer that defines the shape of the object, then have each instance specify a Local-to-World matrix that translates the verts to the position that instance is at. This avoids having a duplicate copy of the vertices around for each instance and you don''t have to change the vertex buffer contents each time your objects move.

Share this post


Link to post
Share on other sites
I thought that might be the way to go about this. That helps me to avoid locking and modifying all of my vertex buffers repeatedly. What about animations, though? Should I use a different index into the vertex buffer for each frame of animation (to allow for mapping uv coordinates to a different portion of the texture)?

Share this post


Link to post
Share on other sites
There are lots of ways to do animations and the method you mention should work fine. I''ve never actually thought about doing it that way before, but it sounds like it should work, and it allows you to animate the UV values as well as the vertex positions as you mentioned, so yeah that''s a good idea.

Share this post


Link to post
Share on other sites