2D in DirectX Graphics

Started by
3 comments, last by EEROOKIE 21 years, 5 months ago
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?
Advertisement
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?
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.
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)?
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.

This topic is closed to new replies.

Advertisement