ImageData
Introduction
Creating Textures
using Texture2D = Microsoft.Xna.Framework.Graphics.Texture2D;
using Color = Microsoft.Xna.Framework.Graphics.Color;
using FlatRedBall.Graphics.Texture;ImageData imageData = new ImageData(32, 32);
imageData.Fill(Color.Blue);
// let's plot some random pixels:
for (int i = 0; i < 50; i++)
{
int randomX = FlatRedBallServices.Random.Next(
imageData.Width);
int randomY = FlatRedBallServices.Random.Next(
imageData.Height);
imageData.SetPixel(randomX, randomY, Color.Yellow);
}
// Create the texture
Texture2D texture2D = imageData.ToTexture2D();
// Give it a name. Make sure this is unique!
texture2D.Name = "MyDynamicTexture";
// We will want to associate the created Texture2D with a
// ContentManager. If you're in a Screen, use the Screen's
// ContentManager. Here we'll just make one up:
FlatRedBallServices.AddDisposable(
texture2D.Name,
texture2D,
"MyContentManager");
// Finally, let's use this Texture so we can actually see it
Sprite sprite = SpriteManager.AddSprite(texture2D);
// Set these numbers higher if using FSB or if you're in pixel
// pixel coordinates:
sprite.ScaleX = 10;
sprite.ScaleY = 10;
Additional Information
ImageData Members
Last updated
Was this helpful?