XNA Creators Club Online
Page 1 of 1 (5 items)
Sort Posts: Previous Next

Sprites in 3d space?

Last post 04-16-2008 5:42 AM by newclyusinju. 4 replies.
  • 04-15-2008 4:59 PM

    Sprites in 3d space?

    Hi,

    I'd like to make a 2d game with camera panning, zooming and rotation (think 'worms'). Presumably the best way to do this is by rendering a lot of quads on a plane and having a camera look directly at the plane. Can anyone point me towards tutorials or other resources to get me started. (What would be really useful would be a version of SpriteBatch that allows me to specify sprite locations in world space rather than screen space.)

    Thanks,
    felix
  • 04-15-2008 5:36 PM In reply to

    Re: Sprites in 3d space?

    you can do what you want with spritebatch easily enough.  what you need to to is have a 'fake' camera:

    public class Camera
    {

        vector2 position;
        vector2 scale;
        float Rotation;


    }

    update the camera's properties as needed and then in your draw call do something like this

    spritebatch.draw( (mySprite.Position - Camera.Position), (mySprite.Rotation- Camera.Rotation), (mySprite.scale- Camera.scale))

    where mySprite.Position is a world position.

    this code wont work it's just to demonstrate the basic idea.  you will quickly find this gets difficult to manage and you'l probably want to implment a screne manager type class/service.

    i'm building an engine that can do all of the things you want at the moment - see my sig for details - and i will update it soon with details of the screenmanager, renderingmanager and all the other bits soon.
    See what I'm up to here
  • 04-15-2008 6:03 PM In reply to

    Re: Sprites in 3d space?

    SpriteBatch can be used to do exactly that, either by passing in a camera transform matrix to your Begin call, or just by manually offsetting the coordinates for each Draw (for instance our Tiled Sprites sample implements a 2D camera that way).
    XNA Framework Developer - blog - homepage
  • 04-16-2008 3:47 AM In reply to

    Re: Sprites in 3d space?

    Thanks for the info guys. Personally I dont like the idea of manually offsetting, scaling and clipping things, isnt the whole point of the 3d pipeline to do that for me much quicker?

    I'll have a look at the tiled sprites tutorial you mentioned and the camera tansform in the Begin call.

    Thanks again
    felix
  • 04-16-2008 5:42 AM In reply to

    Re: Sprites in 3d space?

    You could always render your sprites as billboards in an orthographic projection..

    To manage size easily you could normalise your billboard dimensions & then just use the scale components of your world matrices
     to define the width & height of each billboard in pixels..

    You'd just have the manually batch your rendering & if necessary manually sort by texture too..
    My Game Blog: http://houseofsmash.blogspot.com
    My Blog: http://watchhogstories.wordpress.com
Page 1 of 1 (5 items) Previous Next