Question

I have 2 game objects in my game scene, a character sprite and a background sprite. I passed a scalar matrix into the spritebatch.begin parameter and everything draws fine when scaling by 1 or below. When I scale anywhere above 1, however, my background image does not draw (the character sprite still does). Both the background and character have pretty much the exact same code (except things like position, the image file, etc).

The matrix:

ViewMatrix = Matrix.CreateScale(1.5f); //Anything 1 or below works fine.

I wish I could provide more information, but I'd have no idea what to provide.. I tried searching the web for similar problems and didn't find anything.

Was it helpful?

Solution

Use Matrix.CreateScale(1.5f, 1.5f, 1f) - basically: don't scale the Z axis.


The GPU raster area is in the range (-1, -1, 0) to (1, 1, 1). Only fragments (pixels) falling in this volume are rendered. The Z-axis is the range of your depth buffer. Traditionally a projection matrix takes your scene and projects it into this space.

SpriteBatch's equivalent of a projection matrix takes your scene in "client space" (origin top left corner) and projects it into this space. But it leaves the Z axis alone.

By default, SpriteBatch does not use the depth buffer. But it still gives each sprite quad a Z-position, which is specified by the layerDepth parameter to SpriteBatch.Draw.

The transformation specified in SpriteBatch.Begin is applied after the sprite quad is positioned by Draw, and before the projection.

So normally the valid range for layerDepth is between 0 and 1 (because this falls in the raster volume). But if you apply a custom transformation that modifies the Z-axis of your sprites, the valid range of layerDepth will change.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top