本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.Texture2D.GetData方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.GetData方法的具体用法?C# Texture2D.GetData怎么用?C# Texture2D.GetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Graphics.Texture2D
的用法示例。
在下文中一共展示了Texture2D.GetData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Clip
public static Texture2D Clip(GraphicsDevice gd, Texture2D texture, Rectangle source)
{
var newTexture = new Texture2D(gd, source.Width, source.Height);
var size = source.Width * source.Height;
uint[] buffer = GetBuffer(size);
if (FSOEnvironment.SoftwareDepth)
{
//opengl es does not like this
var texBuf = GetBuffer(texture.Width * texture.Height);
texture.GetData(texBuf);
var destOff = 0;
for (int y=source.Y; y<source.Bottom; y++)
{
int offset = y * texture.Width + source.X;
for (int x = 0; x < source.Width; x++)
{
buffer[destOff++] = texBuf[offset++];
}
}
}
else
{
texture.GetData(0, source, buffer, 0, size);
}
newTexture.SetData(buffer);
return newTexture;
}
示例2: Level
public Level(Texture2D _brick, Texture2D _badGuys, Texture2D _projectile, Texture2D _blank, GraphicsDevice graphicsDevice, SpriteBatch _spriteBatch)
{
spriteBatch = _spriteBatch;
int brick2 = brickSize * brickSize;
singleBrick = new Color[brick2];
beginBrick = new Color[brick2];
contBrick = new Color[brick2];
endBrick = new Color[brick2];
topDoor = new Color[brick2];
botDoor = new Color[brick2];
destructBrick = new Color[brick2];
collectable = new Color[brick2];
openDoor = new AnimatedSprite();
projectile = _projectile;
badGuys = _badGuys;
brick = _brick;
_brick.GetData<Color>(0, new Rectangle(0, 0, brickSize, brickSize), topDoor, 0, brick2);
_brick.GetData<Color>(0, new Rectangle(0, brickSize, brickSize, brickSize), botDoor, 0, brick2);
_brick.GetData<Color>(0, new Rectangle(0, 2 * brickSize, brickSize, brickSize), singleBrick, 0, brick2);
_brick.GetData<Color>(0, new Rectangle(0, 3 * brickSize, brickSize, brickSize), beginBrick, 0, brick2);
_brick.GetData<Color>(0, new Rectangle(0, 4 * brickSize, brickSize, brickSize), contBrick, 0, brick2);
_brick.GetData<Color>(0, new Rectangle(0, 5 * brickSize, brickSize, brickSize), endBrick, 0, brick2);
_brick.GetData<Color>(0, new Rectangle(0, 6 * brickSize, brickSize, brickSize), destructBrick, 0, brick2);
_brick.GetData<Color>(0, new Rectangle(0, 7 * brickSize, brickSize, brickSize), collectable, 0, brick2);
currLvlText = new Texture2D(graphicsDevice, _blank.Width, _blank.Height);
blankLevel = new Color[_blank.Height*_blank.Width];
_blank.GetData<Color>(blankLevel);
currLvlText.SetData<Color>(blankLevel);
}
示例3: GetTextureData
public static uint[] GetTextureData(Texture2D texture)
{
int dataLength = texture.Width * texture.Height;
uint[] pixelData = new uint[dataLength];
texture.GetData<uint>(pixelData);
return pixelData;
}
示例4: Parse
public Level Parse(Texture2D mapImage)
{
Level level = new Level();
_levelScaleFactor = 4;
_imageHeight = mapImage.Height;
_imageWidth = mapImage.Width;
Color[] colorData;
colorData = new Color[_imageWidth * _imageHeight];
mapImage.GetData<Color>(colorData);
for (int y = 0; y < _imageHeight; y++)
{
for (int x = 0; x < _imageWidth; x++)
{
Color currentPixel = colorData[_imageWidth * y + x];
if (currentPixel == Color.White)
continue;
Point position = new Point(x, y);
//Wall if all are the same
if (currentPixel.R == currentPixel.G && currentPixel.G == currentPixel.B)
HandleWall(position, currentPixel, colorData, level);
else if (currentPixel == PLAYER_COLOR)
HandlePlayer(position, currentPixel, colorData, level);
else if (currentPixel == FRIENDLY_COLOR)
HandleFriendly(position, currentPixel, colorData, level);
else if (currentPixel == ENEMY_COLOR)
HandleEnemy(position, currentPixel, colorData, level);
}
}
return level;
}
示例5: IMTexture
public IMTexture(Texture2D texture)
{
Texture = texture;
LODColor = Color.Black;
// If this is a null texture, use a black LOD color.
if (Texture == null)
return;
// Calculate the load color dynamically.
float r = 0, g = 0, b = 0;
Color[] pixelData = new Color[texture.Width * texture.Height];
texture.GetData<Color>(pixelData);
for (int i = 0; i < texture.Width; i++)
for (int j = 0; j < texture.Height; j++)
{
r += pixelData[i + j * texture.Width].R;
g += pixelData[i + j * texture.Width].G;
b += pixelData[i + j * texture.Width].B;
}
r /= texture.Width * texture.Height;
g /= texture.Width * texture.Height;
b /= texture.Width * texture.Height;
LODColor = new Color(r / 256, g / 256, b / 256);
}
示例6: CheckForCollisions
/// <summary>
/// Checks for collision in the bitmap
/// </summary>
/// <param name="collisionTexture">texture you want collision against</param>
/// <param name="checkPoint">point you want to check for collision</param>
/// <returns>collision type</returns>
public CollisionType CheckForCollisions(Texture2D collisionTexture, Point checkPoint)
{
var collisionColors = new Color[collisionTexture.Height * collisionTexture.Width];
collisionTexture.GetData(collisionColors);
var checkIndex = checkPoint.X + checkPoint.Y * collisionTexture.Width;
// Index out of bounds
if (checkIndex > collisionColors.Length - 1)
return CollisionType.Unwalkable;
var detectedColor = collisionColors[checkIndex];
if (detectedColor == BushTile)
return CollisionType.Bush;
if ( detectedColor == HealingHerb )
return CollisionType.HealingHerb;
if (detectedColor == WalkableTile)
return CollisionType.Walkable;
if (detectedColor == TrainerTriggerBushTile)
return CollisionType.TrainerTriggerBush;
if (detectedColor == TrainerTriggerTile)
return CollisionType.TrainerTrigger;
return CollisionType.Unwalkable;
}
示例7: blit
public static void blit(Texture2D src, Rectangle srcRect, Texture2D dest, Rectangle destRect)
{
int count = srcRect.Width * srcRect.Height;
uint[] data = new uint[count];
src.GetData<uint>(0, srcRect, data, 0, count);
dest.SetData<uint>(0, destRect, data, 0, count, SetDataOptions.None);
}
示例8: generateShadedTexture
public static void generateShadedTexture(Color col, Texture2D bsprite, ref Texture2D target)
{
//System.Console.WriteLine("Input colour: " + col.ToString());
try
{
Color[] shades = generateShades(col);
/*System.Console.WriteLine("Output colours: " + shades[0]);
System.Console.WriteLine("\t" + shades[1]);
System.Console.WriteLine("\t" + shades[2]);
System.Console.WriteLine("\t" + shades[3]);
System.Console.WriteLine("\t" + shades[4]);*/
Color[] colArray = new Color[bsprite.Width * bsprite.Height];
bsprite.GetData<Color>(colArray);
for (int c = 0; c < colArray.Length; c++)
{
for (int i = 0; i < 5; i++)
{
if (colArray[c] == BLUE_SHADES[i])
{
colArray[c] = shades[i];
break;
}
}
}
target.SetData<Color>(colArray);
}
catch (System.Exception e)
{
System.Console.OpenStandardError();
System.Console.WriteLine(e.Message);
System.Console.WriteLine(e.StackTrace);
System.Console.Error.Close();
}
//System.Console.WriteLine("Finished texture shading!");
}
示例9: Split
/// <summary>
/// It gets picture and splits it into 9 parts (3x3).
/// </summary>
/// <param name="image">the picture that sholud be splitted</param>
/// <param name="width">into parts with width = <paramref name="width"/></param>
/// <param name="height">into parts with height = height</param>
/// <param name="xCount">rows</param>
/// <param name="yCount">columns</param>
/// <returns></returns>
public List<Shape> Split(Texture2D image, int width, int height, int xCount = 3, int yCount = 3)
{
List<Shape> result = new List<Shape>();
int dataPerPart = width * height;
int uniqueIndexer = 1;
Color[] originalData = new Color[image.Width * image.Height];
image.GetData<Color>(originalData);
for (int y = 0; y < yCount * height; y += height)
for (int x = 0; x < xCount * width; x += width)
{
Texture2D part = new Texture2D(image.GraphicsDevice, width, height);
Color[] partData = new Color[dataPerPart];
for (int py = 0; py < height; py++)
for (int px = 0; px < width; px++)
{
int partIndex = px + py * width;
if (y + py >= image.Height || x + px >= image.Width)
partData[partIndex] = Color.Transparent;
else
partData[partIndex] = originalData[(x + px) + (y + py) * image.Width];
}
part.SetData<Color>(partData);
Shape shape = new Shape(part);
shape.UniqueNumber = uniqueIndexer;
uniqueIndexer++;
result.Add(shape);
}
return result;
}
示例10: FromTextrure
public static Vertices FromTextrure(Texture2D polygonTexture)
{
uint[] data = new uint[polygonTexture.Width * polygonTexture.Height];
polygonTexture.GetData(data);
return PolygonTools.CreatePolygon(data, polygonTexture.Width);
}
示例11: GetVertsFromMapImage
public static List<Vertices> GetVertsFromMapImage( Texture2D image, float scale, out Vector2 origin )
{
uint[] data = new uint[ image.Width * image.Height ];
image.GetData( data );
Vertices textureVertices = PolygonTools.CreatePolygon( data, image.Width, false );
Vector2 centroid = -textureVertices.GetCentroid();
textureVertices.Translate( ref centroid );
origin = -centroid;
//We simplify the vertices found in the texture.
textureVertices = SimplifyTools.ReduceByDistance( textureVertices, 4f );
//Since it is a concave polygon, we need to partition it into several smaller convex polygons
//scale the vertices from graphics space to sim space
//Settings.MaxPolygonVertices = 1000;
var list = BayazitDecomposer.ConvexPartition( textureVertices );
Vector2 vertScale = new Vector2( ConvertUnits.ToSimUnits( 1 ) ) * scale;
foreach ( Vertices vertices in list ) {
vertices.Scale( ref vertScale );
}
return list;
}
示例12: PixelPerfectCollision
private static Boolean PixelPerfectCollision(Rectangle Bounds1, Texture2D Texture1, Rectangle Bounds2, Texture2D Texture2)
{
Color[] bitsA = new Color[Bounds1.Width * Bounds1.Height];
Color[] bitsB = new Color[Bounds2.Width * Bounds1.Height];
Texture1.GetData(bitsA);
Texture2.GetData(bitsB);
int x1 = Math.Max(Bounds1.X, Bounds2.X);
int x2 = Math.Min(Bounds1.X + Bounds1.Width, Bounds2.X + Bounds2.Width);
int y1 = Math.Max(Bounds1.Y, Bounds2.Y);
int y2 = Math.Min(Bounds1.Y + Bounds1.Height, Bounds2.Y + Bounds2.Height);
// For each single pixel in the intersecting rectangle
for (int y = y1; y < y2; ++y)
{
for (int x = x1; x < x2; ++x)
{
// Get the color from each texture
Color a = bitsA[(x - Bounds1.X) + (y - Bounds1.Y) * Texture1.Width];
Color b = bitsB[(x - Bounds2.X) + (y - Bounds2.Y) * Texture2.Width];
if (a.A != 0 && b.A != 0) // If both colors are not transparent (the alpha channel is not 0), then there is a collision
{
return true;
}
}
}
return false;
}
示例13: LoadHeightData
public static float[,] LoadHeightData(Texture2D height_map, ref int terrain_width, ref int terrain_height, ref float min_height, ref float max_height, float height_limit)
{
terrain_width = height_map.Width;
terrain_height = height_map.Height;
Color[] map_colors = new Color[terrain_height * terrain_width];
height_map.GetData<Color>(map_colors);
float[,] height_data = new float[terrain_width, terrain_height];
for(int x=0; x<terrain_width; x++)
{
for(int y=0; y<terrain_height; y++)
{
height_data[x, y] = map_colors[x+y*terrain_width].R;
if (height_data[x, y] > max_height)
max_height = height_data[x, y];
if(height_data[x, y] < min_height)
min_height = height_data[x, y];
}
}
for (int x = 0; x < terrain_width; x++)
{
for(int y=0; y< terrain_height; y++)
{
if (max_height == min_height)
height_data[x, y] = Math.Min(min_height, height_limit);
else
height_data[x, y] = (height_data[x, y] - min_height) / (max_height - min_height) * height_limit;
}
}
return height_data;
}
示例14: BuildVertices
private void BuildVertices(Texture2D heightMap)
{
var heightMapColors = new Color[_vertexCount];
heightMap.GetData(heightMapColors);
float x = _position.X;
float z = _position.Z;
float y = _position.Y;
float maxX = x + _topSize;
for (int i = 0; i < _vertexCount; i++)
{
if (x > maxX)
{
x = _position.X;
z++;
}
y = _position.Y + (heightMapColors[i].R / 2.0f);
var vert = new VertexPositionNormalTexture(new Vector3(x * _scale, y * _scale, z * _scale), Vector3.Zero, Vector2.Zero);
vert.TextureCoordinate = new Vector2(((vert.Position.X - _position.X) / _topSize), ((vert.Position.Z - _position.Z) / _topSize)) / _scale;
Vertices[i] = vert;
x++;
}
}
示例15: Trap
public Trap(Texture2D texture, Vector2 pos)
: base(texture, pos)
{
hitbox = new Rectangle((int)pos.X, (int)pos.Y, texture.Width, texture.Height);
texData = new Color[texture.Width * texture.Height];
texture.GetData(texData);
}