AlfonsAberg

What I want to do is have a camera and sprites with "world coordinates"(x,y and z), and they will affect all sprites position and scale. Is this feature already in the XNA framework or do I have to create an engine myself


Re: XNA Game Studio Express 2d Sprites with depth?

Bill Reiss

You can use one of the SpriteBatch.Draw() methods that accepts layerDepth and then setting SpriteSortMode to BackToFront or FrontToBack in the SpriteBatch.Begin() call. This will run a bit slower than the default SpriteSortMode of Deferred but should give you what you're looking for.




Re: XNA Game Studio Express 2d Sprites with depth?

Shawn Hargreaves - MSFT

The XNA SpriteBatch class doesn't directly support a 2D camera, but it does allow you to draw sprites with arbitrary floating point positions and scales, so you could still use it to draw your graphics after applying your own camera calculation to the position values.





Re: XNA Game Studio Express 2d Sprites with depth?

Joel Martinez

the built-in sprite system does not support what you're asking for ... you'd have to develop it yourself :-)

The FlatRedBall engine, an MDX engine who's XNA port is in development, works exactly like what you're describing.





Re: XNA Game Studio Express 2d Sprites with depth?

AlfonsAberg

Thanks for all your useful answers. I found this tutorial in flash with a 2d camera. This piece of code should be useful:

zoomZ = 100;
shiftX = 0;
shiftY =0;
z0=100;
PZ = {x:50, y:250};


function f3dscale (z) {
var scale = zoomZ*z0/(z0+z);
return scale;
}
function f3dPoint (x, y, z) {
var x3d = (x+shiftX)*f3dscale(z)/100+PZ.x;
var y3d = (y+shiftY)*f3dscale(z)/100+PZ.y;
var pt = {x:x3d, y:y3d};
return pt;
}

So, for a ball with x,y,z

_x=f3dPoint(x,y,z).x;
_y=f3dPoint(x,y,z).y;
_xscale=_yscale=f3dscale(z);