tags:

views:

28

answers:

2

As I've studied so far, there are 2 ways to draw in xna; using spritebatch or putting items onto the 3d world and then use a camera to render it.

Currently, I'm working on my 2.5D game. I'm using a mechanics that makes the deeper sprite translates slower, so that it looks like there is really depth there in the game.

However, considering effects i.e. postprocessing, it could be some problem if i want to render those effect onto the middle level of depth, i.e. render it onto my character with depth = 0.5, while there is a foreground tree at depth = 0.8.

Thus, I'm considering rendering my game in the real 3D world.

However, since i've searched for the way to put my sprite and animate it in the 3d world so far, I haven't found one. (It might be because I didn't know the correct keywords.) The closest topics I found is about PointSprite, which is now removed from XNA4.0, so I couldn't implement it that way.

My question is, how could I render my animate sprite (i.e. character movement) in 3D world.

Thanks, Dome

A: 

The trick is to exactly what you've been doing thus far excapt instead of using spritebatch to draw "directly" to the screen, you draw the 2d images onto flat "sheets" in the 3d world instead (with each "sheet" consisting of two triangles to form a square).

I would suggest looking at the samples for building quads, textures and possibly render targets on the create.msdn.com site as a starting point.

lzcd
A: 

New in XNA 4.0, SpriteBatch can be used with BasicEffect.

This blog post explains it. It also provides some sample code that mimics the default SpriteBatch functionality through BasicEffect - but you can pass in your own matrices for a 3D world.

Specifically: your "world" matrix will describe the position of the plane where the sprites are drawn, in 3D space. The "view" matrix will describe your camera's view of the world. And the "project" matrix will be a 3D projection matrix (probably from Matrix.CreatePerspective).

By the way, the name of the effect you are describing is "parallax scrolling". It is not the same thing as real 3D (and 2.5D is also something different again).

If you want to apply effects to only certain layers in a scene: Well you can either apply the effect to those sprites directly by passing an effect with a pixel shader to SpriteBatch.Begin. Or if your effects really are post-processing effects (ie: apply to the whole screen) then you could use a render target to render that particular layer off-screen, and then render it back to the screen with your effect.

Andrew Russell