本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.Texture2D.SetData方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.SetData方法的具体用法?C# Texture2D.SetData怎么用?C# Texture2D.SetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Graphics.Texture2D
的用法示例。
在下文中一共展示了Texture2D.SetData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTexture
public Texture2D GetTexture(string name)
{
if (!_initialized)
Initialize();
if (_textures.ContainsKey(name))
return _textures[name];
else
{
Rectangle r = RectangleFromName(name);
if (r.Width > 1)
{
Color[] colors = new Color[_width * _height];
_texture.GetData<Color>(0, r, colors, 0, _width * _height);
Texture2D tex = new Texture2D(MainApplication.Instance.GraphicsDevice, _width, _height);
tex.SetData<Color>(0, new Rectangle(0, 0, _width, _height), colors, 0, _width * _height);
_textures.Add(name, tex);
return tex;
}
return null;
}
}
示例2: Load
public static void Load(ContentManager content)
{
Player = content.Load<Texture2D>("Player");
Pixel = new Texture2D(Player.GraphicsDevice, 1, 1);
Pixel.SetData(new[] { Color.White });
}
示例3: Inventory
public Inventory(int SCREEN_WIDTH, int SCREEN_HEIGHT, Pantheon gameReference)
{
locationBoxes = new List<Rectangle>();
equippedBoxes = new List<Rectangle>();
types = new List<int>();
infoBox = new Rectangle();
movingBox = new Rectangle();
trashBox = new Rectangle();
tempStorage = new Item();
this.SCREEN_WIDTH = SCREEN_WIDTH;
this.SCREEN_HEIGHT = SCREEN_HEIGHT;
SetBoxes();
selected = -1;
hoveredOver = -1;
color = new Color(34, 167, 222, 50);
trashColor = Color.White;
inventorySelector = gameReference.Content.Load<Texture2D>("Inventory/InvSelect");
trashCan = gameReference.Content.Load<Texture2D>("Inventory/TrashCan");
nullImage = new Texture2D(gameReference.GraphicsDevice, 1,1);
nullImage.SetData(new[] { new Color(0,0,0,0) });
}
示例4: ApplyBorderLabel
public static Texture2D ApplyBorderLabel(this Texture2D texture, BorderStyle style)
{
Texture2D newTexture = new Texture2D(texture.GraphicsDevice, texture.Width, texture.Height);
Color[] data = texture.GetColorData();
switch (style)
{
case (BorderStyle.FixedSingle):
for (int y = 0; y < texture.Height; y++)
{
for (int x = 0; x < texture.Width; x++)
{
if (y == 0 || x == 0 || y == texture.Height - 1 || x == texture.Width - 1)
{
data[x + y * texture.Width] = Color.DimGray;
}
}
}
newTexture.SetData(data);
return newTexture;
case (BorderStyle.Fixed3D):
for (int y = 0; y < texture.Height; y++)
{
for (int x = 0; x < texture.Width; x++)
{
if (y == 0 || x == 0) data[x + y * texture.Width] = Color.DarkSlateGray;
else if (y == texture.Height - 1 || x == texture.Width - 1) data[x + y * texture.Width] = Color.White;
}
}
newTexture.SetData(data);
return newTexture;
default:
return texture;
}
}
示例5: ApplyBorderButton
public static Texture2D ApplyBorderButton(this Texture2D texture, ButtonStyle type)
{
Texture2D newTexture = new Texture2D(texture.GraphicsDevice, texture.Width, texture.Height);
Color[] data = texture.GetColorData();
switch (type)
{
case (ButtonStyle.Default):
for (int y = 0; y < texture.Height; y++)
{
for (int x = 0; x < texture.Width; x++)
{
if (y == 0 || x == 0 || y == texture.Height - 1 || x == texture.Width - 1)
{
data[x + y * texture.Width] = Color.CornflowerBlue;
}
}
}
newTexture.SetData(data);
return newTexture;
case (ButtonStyle.Hover):
for (int y = 0; y < texture.Height; y++)
{
for (int x = 0; x < texture.Width; x++)
{
if (y == 0 || x == 0 || y == texture.Height - 1 || x == texture.Width - 1)
{
data[x + y * texture.Width] = Color.DimGray;
}
}
}
newTexture.SetData(data);
return newTexture;
case (ButtonStyle.Click):
for (int y = 0; y < texture.Height; y++)
{
for (int x = 0; x < texture.Width; x++)
{
if (y == 0 || x == 0 || y == texture.Height - 1 || x == texture.Width - 1)
{
data[x + y * texture.Width] = Color.Black;
}
else data[x + y * texture.Width] = data[x + y * texture.Width].Add(0, -10, -10, -10);
}
}
newTexture.SetData(data);
return newTexture;
default:
return texture;
}
}
示例6: CreateWhitePixel
private static Texture2D CreateWhitePixel(GraphicsDevice graphicsDevice)
{
whitePixel = new Texture2D(graphicsDevice, 1, 1);
whitePixel.SetData(new[] { Color.White });
return whitePixel;
}
示例7: init
// Methods
public static void init(GraphicsDevice graphDev, SpriteBatch spriteBatch)
{
pointTexture = new Texture2D(graphDev, 1, 1, false, SurfaceFormat.Color);
pointTexture.SetData<Color>(new Color[] { defaultColor });
sb = spriteBatch;
}
示例8: LoadContent
protected override void LoadContent()
{
base.LoadContent();
sb = new SpriteBatch(GraphicsDevice);
bgcolor = new Texture2D(GraphicsDevice, 1, 1);
bgcolor.SetData(new Color[] { Color.Purple });
zones.Add(Game.Content.Load<Texture2D>("zoneTitle"));
zones.Add(Game.Content.Load<Texture2D>("zoneCandyMunching"));
zones.Add(Game.Content.Load<Texture2D>("zoneHumanRepellant"));
zones.Add(Game.Content.Load<Texture2D>("zoneCallship"));
zones.Add(Game.Content.Load<Texture2D>("zoneLanding"));
zones.Add(Game.Content.Load<Texture2D>("zoneUp"));
zones.Add(Game.Content.Load<Texture2D>("zoneLeft"));
zones.Add(Game.Content.Load<Texture2D>("zoneRight"));
zones.Add(Game.Content.Load<Texture2D>("zoneDown"));
zones.Add(Game.Content.Load<Texture2D>("zoneCallElliott"));
zones.Add(Game.Content.Load<Texture2D>("zonePitfall"));
zones.Add(Game.Content.Load<Texture2D>("zoneQuestion"));
pieces.Add(Game.Content.Load<Texture2D>("pieces0"));
pieces.Add(Game.Content.Load<Texture2D>("pieces1"));
pieces.Add(Game.Content.Load<Texture2D>("pieces2"));
pieces.Add(Game.Content.Load<Texture2D>("pieces3"));
etGame.Components.Add(clock);
currentZone = zones[0];
}
示例9: init
// Methods
public static void init(GraphicsDevice graphDev, SpriteBatch spriteBatch)
{
// init pointTexture
pointTexture = new Texture2D(graphDev, 1, 1, false, SurfaceFormat.Color);
pointTexture.SetData<Color>(new Color[] { defaultColor });
// init circleTexture
circleTexture = new Texture2D(graphDev, circleRadius, circleRadius);
Color[] colorData = new Color[circleRadius * circleRadius];
float diam = circleRadius / 2f;
float diamsq = diam * diam;
for (int x = 0; x < circleRadius; x++)
{
for (int y = 0; y < circleRadius; y++)
{
int index = x * circleRadius + y;
Vector2 pos = new Vector2(x - diam, y - diam);
if (pos.LengthSquared() <= diamsq)
{
colorData[index] = defaultColor;
}
else
{
colorData[index] = Color.Transparent;
}
}
}
circleTexture.SetData(colorData);
// spriteBatch reference
sb = spriteBatch;
}
示例10: Draw
public override void Draw(GameTime gameTime)
{
Rectangle aPositionAdjusted;
if (drawRoadmap)
{
Texture2D blank = new Texture2D(game.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
blank.SetData(new[] { Color.White });
spriteBatch.Begin();
foreach (Configuration conf in samples)
{
aPositionAdjusted = new Rectangle((int)conf.X + (int)(conf.Width / 2), (int)conf.Y + (int)(conf.Height / 2), (int)conf.Width, (int)conf.Height);
spriteBatch.Draw(game.obstacleTexture, aPositionAdjusted, new Rectangle(0, 0, 2, 6), Color.Magenta, conf.Rotation, new Vector2(2 / 2, 6 / 2), SpriteEffects.None, 0);
foreach (Configuration nbConf in conf.neighbors)
{
float angle = (float)Math.Atan2(nbConf.CollisionRectangle.position.Y - conf.CollisionRectangle.position.Y, nbConf.CollisionRectangle.position.X - conf.CollisionRectangle.position.X);
float length = Vector2.Distance(conf.CollisionRectangle.position, nbConf.CollisionRectangle.position);
spriteBatch.Draw(blank, new Vector2(conf.CollisionRectangle.position.X + conf.Width/2, conf.CollisionRectangle.position.Y+ conf.Height/2), null, Color.Black, angle, Vector2.Zero, new Vector2(length, (float)1), SpriteEffects.None, 0);
}
}
spriteBatch.End();
}
base.Draw(gameTime);
}
示例11: GetClearTexture2D
/// <summary>
/// Gets a 1x1 texture with a clear transparent pixel in it.
/// </summary>
/// <param name="batch">The batch to create the texture from.</param>
/// <returns>The texture</returns>
public static Texture2D GetClearTexture2D(SpriteBatch batch)
{
Texture2D lineTexture = new Texture2D(batch.GraphicsDevice, 1, 1);
int[] intColor = { (int)Color.White.PackedValue };
lineTexture.SetData(intColor);
return lineTexture;
}
示例12: Line
public Line(GraphicsDeviceManager graphics)
{
pixel = new Texture2D(graphics.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
pixel.SetData(new[] { Color.White });
point1 = Vector2.Zero;
point2 = Vector2.Zero;
}
示例13: drawCircle
public void drawCircle(SpriteBatch spriteBatch, Color c, Rectangle rec, double percent)
{
int radius = 20;
int outerRadius = radius * 2 + 2;
Texture2D texture = new Texture2D(Program.game.GraphicsDevice, outerRadius, outerRadius);
Color[] data = new Color[outerRadius * outerRadius];
for (int i = 0; i < data.Length; i++)
data[i] = Color.Transparent;
double angleStep = 1f / radius;
for (double angle = 0; angle < Math.PI * 2 * percent; angle += angleStep)
{
int x = (int)Math.Round(radius + radius * Math.Cos(angle + 3 * Math.PI / 2));
int y = (int)Math.Round(radius + radius * Math.Sin(angle + 3 * Math.PI / 2));
data[y * outerRadius + x + 1] = Color.White;
}
texture.SetData(data);
spriteBatch.Draw(texture, rec, c);
}
示例14: Draw
public override void Draw(SpriteBatch spriteBatch, GraphicsDevice graphics)
{
Texture2D redPixel = new Texture2D(graphics, 1, 1);
Texture2D blackPixel = new Texture2D(graphics, 1, 1);
Color[] redData = { Color.Red };
Color[] blackData = { Color.Black };
redPixel.SetData<Color>(redData);
blackPixel.SetData<Color>(blackData);
Rectangle healthContainer = new Rectangle((int)position.X, (int)position.Y - 10, width, 5);
int borderWidth = 1;
// Draw health segments inside of health container
for (int i = 0; i < healthPoints; i++)
{
int segmentWidth = (int)Math.Ceiling((double)width / maxHealthPoints);
int left = (int)position.X + (int)(i * segmentWidth);
if (i + 1 == maxHealthPoints)
segmentWidth = width - (i * segmentWidth);
Rectangle segment = new Rectangle(left, (int)position.Y - 10, segmentWidth, 5);
spriteBatch.Draw(redPixel, segment, Color.White);
}
spriteBatch.Draw(blackPixel, new Rectangle(healthContainer.Left, healthContainer.Top, borderWidth, healthContainer.Height), Color.White); // Left
spriteBatch.Draw(blackPixel, new Rectangle(healthContainer.Right, healthContainer.Top, borderWidth, healthContainer.Height), Color.White); // Right
spriteBatch.Draw(blackPixel, new Rectangle(healthContainer.Left, healthContainer.Top, healthContainer.Width, borderWidth), Color.White); // Top
spriteBatch.Draw(blackPixel, new Rectangle(healthContainer.Left, healthContainer.Bottom, healthContainer.Width, borderWidth), Color.White); // Bottom
}
示例15: Draw
public void Draw(SpriteBatch spriteBatch)
{
if (BGTexture == null)
{
BGTexture = new Texture2D(spriteBatch.GraphicsDevice, 1, 1);
BGTexture.SetData(new Color[] {Color.White});
}
// draw the background
Rectangle bg = new Rectangle(Game1.ScreenWidth / 4, Game1.ScreenHeight / 4, Game1.ScreenWidth / 2, Game1.ScreenHeight / 2);
spriteBatch.Draw(BGTexture, bg, Color.Black);
// draw each option
int yOffset = bg.Height / Options.Length;
int yPos = bg.Top + (yOffset / 2);
foreach (String opt in Options)
{
Vector2 size = Game1.Font.MeasureString(opt);
Vector2 pos = new Vector2((Game1.ScreenWidth / 2) - (size.X / 2), yPos - (size.Y / 2));
spriteBatch.DrawString(Game1.Font, opt, pos, Color.White);
yPos += yOffset;
}
// draw the selection box
Vector2 selTextSize = Game1.Font.MeasureString(Options[Position]);
int selThickness = yOffset / 10;
Rectangle selArea = new Rectangle(bg.Left, bg.Top + yOffset * Position, bg.Width, yOffset);
Border b = new Border(selArea, selThickness, Color.Green);
b.Draw(spriteBatch);
}