var background = Content.Load<Texture2D>("stars");
var spriteBatch = new SpriteBatch(GraphicsDevice);
var renderTarget = new RenderTarget2D(
,
GraphicsDevice.PresentationParameters.BackBufferWidth,
GraphicsDevice.PresentationParameters.BackBufferHeight,
GraphicsDevicefalse,
.PresentationParameters.BackBufferFormat,
GraphicsDevice.Depth24); DepthFormat
.SetRenderTarget(renderTarget); GraphicsDevice
.SetRenderTarget(null); GraphicsDevice
.Begin();
spriteBatch// Draw background texture to the current Render Target
.Draw(background, new Rectangle(0, 0, 800, 480), Color.White);
spriteBatch// Draw another Render Target to the current Render Target
.Draw(renderTarget, new Rectangle(0, 0, 800, 480), Color.White);
spriteBatch.End(); spriteBatch
= new Texture2D(GraphicsDevice, 100, 100);
_texture
var data = new uint[100 * 100];
for (int a = 0; a < 100 * 100; a += 4)
{
[a] = 0xFF000000;
data[a + 1] = 0xFF000000;
data[a + 2] = 0xFFFFFFFF;
data[a + 3] = 0xFFFFFFFF;
data}
.SetData(data); _texture
NB: data is copied from the array rather than ‘pointed’ to, so changing the underlying array won’t update the texture.
For 32-bit SurfaceFormat.Color
, data format = 0xAABBGGRR, examples:
Update
is called a fixed number of times per second. Draw
may be called less frequently if the game is lagging.
The rate at which Update
is called is set by TargetElapsedTime
.