Click or drag to resize
DigitalRuneSprites (Images and Text)

This topic contains the following sections:

Defining sprites

A sprite is a 2D image, such as a bitmap or a text. Sprites are positioned in world space, but rendered in screen space. That means, a 16x16 pixel image is usually exactly 16x16 pixel on screen. (Internally the images and texts are rendered using the XNA SpriteBatch, hence the name.)

Here is an example of a 2D sprite in a 3D scene:

Sprite

There are two types of sprites: ImageSprites and TextSprites.

A sprite is positioned in world space by creating a new SpriteNode and adding it to a 3D scene. Sprite nodes support simple hit testing. I.e. it is easy to check whether the mouse cursor has hit a certain sprite node. See SpriteNode for more information.

DigitalRune.Graphics (Sprites)
Class Diagram: Sprites
Rendering sprites

The SpriteRenderer is a SceneNodeRenderer that handles SpriteNodes.

Internally, the SpriteRenderer is basically just a wrapper around XNA's SpriteBatch. It converts the positions of the sprite nodes from world space to screen space and draws the images and texts using to the SpriteBatch.

Example:

C#
// Set desired depth-stencil and blend states.
graphicsDevice.DepthStencilState = DepthStencilState.None;
graphicsDevice.BlendState = BlendState.AlphaBlend;

// Render a list of sprite nodes.
spriteRenderer.Render(sceneNodes, context, RenderOrder.BackToFront);