本文整理汇总了C#中GraphicsDevice.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# GraphicsDevice.Clear方法的具体用法?C# GraphicsDevice.Clear怎么用?C# GraphicsDevice.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphicsDevice
的用法示例。
在下文中一共展示了GraphicsDevice.Clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawObjects
public override void DrawObjects(GraphicsDevice graphicDevice, SpriteBatch spriteBatch, ContentManager content)
{
graphicDevice.Clear(Color.CornflowerBlue);
SpriteFont newFont = content.Load<SpriteFont>(@"Fonts/Text");
spriteBatch.Begin();
this.controlScreenBackgroundPosition = new Vector2(0, 0);
spriteBatch.Draw(this.controlScreenBackgroundTexture, this.controlScreenBackgroundPosition, Color.White);
if (this.controlScreenItems.Count < 1)
{
// Back planket and text;
this.buttonPosition = new Vector2(840, 660);
this.controlScreenItems.Add(new MenuItems(this.button, this.buttonPosition, "Back", newFont, false));
}
this.controlScreenItems[this.selectedEntry].Selected = true;
foreach (var item in this.controlScreenItems)
{
item.DrawMenuItems(spriteBatch, new Color(248, 218, 127));
}
this.DrawCursor(spriteBatch);
spriteBatch.End();
}
示例2: addarea
public void addarea(int left, int top, int width, int height,GraphicsDevice device,SpriteBatch batch)
{
for (int I = left; I < left + width; I++)
{
for (int J = top; J < top + height; J++)
{
tilearray[I, J] = new tile();
}
}
RenderTarget2D target = new RenderTarget2D(device, 4096, 4096);
device.SetRenderTarget(target);
device.Clear(Color.Transparent);
batch.Begin();
for (int X = 0; X < 256; X++)
{
for (int Y = 0; Y < 256; Y++)
{
if (tilearray[X, Y] != null)
{
batch.Draw(tiletexture, new Vector2(X*8, Y*8), Color.White);
}
}
}
batch.End();
tileoverlay = (Texture2D)target;
device.SetRenderTarget(null);
device.Clear(Color.CornflowerBlue);
}
示例3: Draw
public override void Draw(GraphicsDevice gd)
{
gd.Clear(Color.White);
//This block of code is a necessary ritual for the FOVs. Just leave it be.
gd.BlendState = BlendState.Opaque;
gd.DepthStencilState = DepthStencilState.Default;
gd.SamplerStates[0] = SamplerState.LinearWrap;
Matrix projection = Matrix.CreateOrthographicOffCenter(0, gd.Viewport.Width, gd.Viewport.Height, 0, 0, 1);
Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);
basicEffect.World = Matrix.Identity;
basicEffect.View = Matrix.Identity;
basicEffect.Projection = halfPixelOffset * projection;
basicEffect.VertexColorEnabled = true;
gd.RasterizerState = RasterizerState.CullNone;
if(!HideOutGame.LEVEL_DESIGN_MODE)
npcController.DrawFOVs(gd, basicEffect);
// TODO: Add your drawing code here
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearWrap, null, null);
spriteBatch.Draw(bgTexture, new Rectangle(0 - HideOutGame.SCREEN_OFFSET_X, 0 - HideOutGame.SCREEN_OFFSET_Y, GAME_WIDTH, GAME_HEIGHT), new Rectangle(0, 0, GAME_WIDTH, GAME_HEIGHT), Color.Green);
obstacleController.Draw(spriteBatch);
itemController.Draw(spriteBatch);
npcController.Draw(spriteBatch);
playerController.Draw(spriteBatch);
displayController.Draw(spriteBatch);
displayController.drawStats(playerController.thePlayer.currentHunger, playerController.thePlayer.currentThirst, spriteBatch);
//_fontRenderer.DrawText(spriteBatch, 50, 50, "Hello World!");
spriteBatch.End();
}
示例4: Draw
public void Draw(GameTime gameTime, GraphicsDevice graphicsDevice)
{
graphicsDevice.Clear(Color.White);
texDraw.Parameters["tex"].SetValue(bgImg);
texDraw.Techniques[0].Passes[0].Apply();
qR.RenderQuad(graphicsDevice, -Vector2.One, Vector2.One, new Vector2(1.0f / Game1.width, 1.0f / Game1.height));
Game1.SpriteBatch.Begin();
clientState.Draw(gameTime);
clientBox.Draw();
serverBox.Draw();
if (clientState.ship != null)
{
current.Height = ((clientState.ship.health * 8) / 10);
current.Y = 82 - current.Height;
healthrect.Height = (clientState.ship.health * 8);
}
Game1.SpriteBatch.Draw(healthbar, current, healthrect, Color.White, 0, Vector2.Zero, SpriteEffects.FlipVertically, 0);
if (clientState.overlay != null)
{
clientState.overlay.Draw();
}
Game1.SpriteBatch.End();
}
示例5: Draw
public void Draw(SpriteBatch spriteBatch, GraphicsDevice graphicsDevice, GameTime gameTime, ScreenInfo screenInfo)
{
//Prepare IRR call
irr.Draw();
graphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.AnisotropicClamp, DepthStencilState.Default, RasterizerState.CullNone, null, camera.GetViewTransformationMatrix());
//IRR only - mBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.AnisotropicClamp, DepthStencilState.Default, RasterizerState.CullNone, null, renderer.GetTransformationMatrix());
// If we're in a level draw that level
if (curLevel != null && curLevel.IsLevelLoaded())
{
curLevel.DrawLevel(spriteBatch, camera, screenInfo);
}
if (playerShip != null)
playerShip.Draw(spriteBatch, curLevel.GetLevelWidth(), curLevel.GetLevelHeight());
foreach (Ship enemy in enemyShips)
{
enemy.Draw(spriteBatch, curLevel.GetLevelWidth(), curLevel.GetLevelHeight());
}
Globals.gPrimitives.DrawAllPrimitives(spriteBatch);
spriteBatch.End();
}
示例6: Draw
//draws menu items
public void Draw(GraphicsDevice graphics, SpriteBatch spriteBatch)
{
graphics.Clear(Color.Black);
List<Button> buttonstemp = new List<Button>();
spriteBatch.Begin();
Vector2 location = position;
for (int i = 0; i < menuItems.Length; i++)
{
Vector2 stringSize = spriteFont.MeasureString(menuItems[i]);
int width = Convert.ToInt32(stringSize.X + 200);
int height = Convert.ToInt32(stringSize.Y + 50);
Button button = new Button("pixel", location, new Rectangle(0, 0, width, height));
buttonstemp.Add(button);
button.Draw(spriteBatch);
spriteBatch.DrawString(
spriteFont,
menuItems[i],
location,
fontColor);
location.Y += spriteFont.LineSpacing + 55;
}
spriteBatch.End();
buttons = buttonstemp;
}
示例7: Draw
//
// Draw
//
public void Draw(GraphicsDevice graphics, SpriteBatch batch)
{
// Clear screen to black
graphics.Clear(Color.Black);
batch.Begin();
for (int i = 0; i < nicks.Count; i++) {
batch.DrawString(font, nicks[i], new Vector2(20, (i * (cardHeight + 4)) + 77), Color.White);
}
for (int i = 0; i < nicks.Count; i++) {
batch.DrawString(font, "Ready", new Vector2(20, (i * (cardHeight + 4)) + 100), ready[i] ? Color.Yellow : Color.Gray);
}
// Let Back button draw itself
btnBack.Draw(batch);
if (showReadyButton) {
btnReady.Draw(batch);
}
if (showStartButton /* && AllPlayersReady() */) {
btnStart.Draw(batch);
}
batch.End();
}
示例8: Initialize
protected override void Initialize()
{
graphics.IsFullScreen = false;
graphics.PreferredBackBufferWidth = width;
graphics.PreferredBackBufferHeight = height;
graphics.ApplyChanges();
Window.Title = "Exercise I.7";
this.IsMouseVisible = true;
spriteBatch = new SpriteBatch(GraphicsDevice);
device = graphics.GraphicsDevice;
rt = new RenderTarget2D(GraphicsDevice,
width,
height,
false,
device.PresentationParameters.BackBufferFormat,
DepthFormat.Depth24,
0,
RenderTargetUsage.PreserveContents);
device.SetRenderTarget(rt);
device.Clear(Color.Black);
device.SetRenderTarget(null);
Drawing.init(device, spriteBatch);
Stats.init();
w = new Walker(width, height);
base.Initialize();
}
示例9: Draw
public void Draw(SpriteBatch sb, GraphicsDevice gd)
{
gd.Clear(Color.MidnightBlue);
bttnLogin.Draw(sb);
bttnRegister.Draw(sb);
bttnPlay.Draw(sb);
}
示例10: FromLabels
public static Texture2D FromLabels(KeyValuePair<string, Color>[] labels, SpriteFont font, Size size, GraphicsDevice device)
{
RenderTarget2D target = new RenderTarget2D(device, size.Width, size.Height);
SpriteBatch sb = new SpriteBatch(device);
device.SetRenderTarget(target);
device.Clear(Color.Transparent);
sb.Begin();
for (int i = 0; i < labels.Length; i++)
{
string prevString = string.Join(" ", labels.Select(l => l.Key).ToArray(), 0, i);
if (i > 0) prevString += " ";
float x = 1 + font.MeasureString(prevString).X;
sb.DrawString(font, labels[i].Key, new Vector2(x, 1), labels[i].Value, 0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
}
sb.End();
device.SetRenderTarget(null);
Texture2D texture = new Texture2D(device, size.Width, size.Height);
Color[] colorData = target.GetColorData();
texture.SetData(colorData);
target.Dispose();
return texture;
}
示例11: FromText
public static Texture2D FromText(string text, SpriteFont font, Color color, Size size, bool multiLine, int lineStart, GraphicsDevice device)
{
string[] drawAbleText = multiLine ? text.Split(new string[1] { "\n" }, StringSplitOptions.None) : new string[1] { text };
RenderTarget2D target = new RenderTarget2D(device, size.Width, size.Height);
SpriteBatch sb = new SpriteBatch(device);
device.SetRenderTarget(target);
device.Clear(Color.Transparent);
sb.Begin();
for (int i = lineStart; i < drawAbleText.Length; i++)
{
float y = 1 + (i - lineStart) * font.GetHeight();
sb.DrawString(font, drawAbleText[i], new Vector2(1, y), color, 0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
}
sb.End();
device.SetRenderTarget(null);
Texture2D texture = new Texture2D(device, size.Width, size.Height);
Color[] colorData = target.GetColorData();
texture.SetData(colorData);
target.Dispose();
sb.Dispose();
return texture;
}
示例12: CreateTextureAtlasAsset
public TextureAtlasAsset CreateTextureAtlasAsset(
string name,
GraphicsDevice graphicsDevice,
IEnumerable<TextureAsset> textures)
{
if (name == null) throw new ArgumentNullException("name");
if (graphicsDevice == null) throw new ArgumentNullException("graphicsDevice");
if (textures == null) throw new ArgumentNullException("textures");
var textureArray = textures.ToArray();
var size = this.CalculateSizeForTextures(textureArray);
var mappings = new Dictionary<string, Rectangle>();
var renderTarget = new RenderTarget2D(graphicsDevice, (int)size.X, (int)size.Y);
try
{
var x = 0;
var y = 0;
graphicsDevice.SetRenderTarget(renderTarget);
graphicsDevice.Clear(Color.Transparent);
using (var spriteBatch = new SpriteBatch(graphicsDevice))
{
spriteBatch.Begin();
foreach (var texture in textureArray)
{
if (texture.Texture.Width == 16 ||
texture.Texture.Height == 16)
{
spriteBatch.Draw(texture.Texture, new Vector2(x, y));
mappings.Add(texture.Name, new Rectangle(x, y, 16, 16));
x += 16;
if (x >= size.X)
{
x = 0;
y += 16;
}
}
}
spriteBatch.End();
}
}
catch (InvalidOperationException)
{
}
graphicsDevice.SetRenderTarget(null);
graphicsDevice.BlendState = BlendState.Opaque;
graphicsDevice.DepthStencilState = DepthStencilState.Default;
graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
return new TextureAtlasAsset(
name,
renderTarget,
mappings);
}
示例13: AccumulateLights
private void AccumulateLights(IEnumerable<ILightProvider> lights, SpriteBatch sb, GraphicsDevice graphicsDevice)
{
graphicsDevice.SetRenderTarget(_accumulatorRT);
graphicsDevice.Clear(Color.Black);
foreach (var light in lights)
{
sb.Begin(SpriteSortMode.Immediate, BlendState.Additive, SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, _lightAccumulatorFX, GameVariables.CameraZoomMatrix);
var normalizedPosition = new Vector2(light.Position.X / _accumulatorRT.Width,
light.Position.Y / _accumulatorRT.Height);
_lightAccumulatorFX.Parameters["lightPosition"].SetValue(normalizedPosition);
_lightAccumulatorFX.Parameters["lightRadius"].SetValue(light.LightRadius);
_lightAccumulatorFX.Parameters["lightIntensity"].SetValue(light.LightIntensity);
sb.Draw(_screenTex, new Rectangle(0, 0, _accumulatorRT.Width, _accumulatorRT.Height), Color.White);
sb.End();
}
graphicsDevice.SetRenderTarget(null);
//if (lights.Any())
//{
// using (var stream = new FileStream("output.png", FileMode.OpenOrCreate))
// {
// _accumulatorRT.SaveAsPng(stream, _accumulatorRT.Width, _accumulatorRT.Height);
// }
//}
}
示例14: UIRenderPlane
public UIRenderPlane(UISpriteBatch batch, Promise<Texture2D> texture)
{
this.GD = batch.GraphicsDevice;
this.Target = batch.GetBuffer();
this.Texture = texture;
this.Batch = batch;
//GD.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents;
/** Switch the render target **/
Batch.Pause();
GD.SetRenderTarget(0, Target);
GD.Clear(Color.TransparentBlack);
Batch.Resume();
/**
batch.Pause();
var buffer = batch.GetBuffer();
var gd = GameFacade.GraphicsDevice;
var renderTarget = gd.GetRenderTarget(0);
gd.SetRenderTarget(0, buffer);
batch.Resume();
gd.render
//gd.Clear(Color.TransparentBlack);**/
}
示例15: draw
public void draw(SpriteBatch sprite, GraphicsDevice brush)
{
sprite.Begin();
brush.Clear(Color.Green);
sprite.Draw(theBackyard, backGround, Color.White);
//sprite.Draw(door, woodsBoundary, Color.White);
sprite.Draw(bear, location, sourceRect, Color.White, 0f, origin, 1.0f, SpriteEffects.None, 0);
if (playerRect.Intersects(boss3Advice))
{
sprite.DrawString(tips, "There HE is, you're probably not strong enough..", new Vector2(250.0f, 400.0f), Color.White);
}
if (playerRect.Intersects(woodsAdvice))
{
sprite.DrawString(tips, "The enemies here are more your speed", new Vector2(250.0f, 400.0f), Color.White);
}
//sprite.Draw(player, playerRect, Color.White);
//sprite.Draw(door, house, Color.White);
//sprite.Draw(door, boss3, Color.White);
sprite.End();
}