IDrawableBatch
Introduction
Code Example
public class DrawableBatchExample : PositionedObject, IDrawableBatch
{
// Even though this IDB doesn't use textures, we'll use a textured vert
// to make it easier to expand
VertexPositionColorTexture[] verts;
BasicEffect effect;
public bool UpdateEveryFrame
{
get
{
return true;
}
}
public DrawableBatchExample()
{
verts = new VertexPositionColorTexture[3];
verts[0].Position = new Microsoft.Xna.Framework.Vector3(-200, -200, 0);
verts[1].Position = new Microsoft.Xna.Framework.Vector3(0, 150, 0);
verts[2].Position = new Microsoft.Xna.Framework.Vector3(200, -200, 0);
verts[0].Color = Color.Red;
verts[1].Color = Color.Green;
verts[2].Color = Color.Blue;
effect = new BasicEffect(FlatRedBallServices.GraphicsDevice);
// The effect controls which properties are considered when DrawUserPrimitives
// is called below. VertexColorEnabled must be set to true to get the triangle's
// vertex colors to show up. If this is false, the triangle will be white.
effect.VertexColorEnabled = true;
}
public void Destroy()
{
}
public void Draw(Camera camera)
{
var graphicsDevice = FlatRedBallServices.GraphicsDevice;
// Setting the view and projection makes the IDrawableBatch
// render using FRB's camera settings. Usually IDrawableBatches
// should use the argument camera's view and projection matrices
effect.View = camera.View;
effect.Projection = camera.Projection;
foreach (var pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
graphicsDevice.DrawUserPrimitives(
// Render a triangle:
PrimitiveType.TriangleList,
// The array of verts that we want to render
verts,
// The offset, which is 0 since we want to start
// at the beginning of the verts array
0,
// The number of triangles to draw
1);
}
}
public void Update()
{
}
}
Drawing SpriteBatch in FlatRedBall Coordinates
Invalid IDrawableBatch Actions
Changing Viewport
Calling SetRenderTarget
IDrawableBatches and the SpriteManager
UpdateEveryFrame
Update
Draw
Destroy
Community Source Code
Last updated
Was this helpful?