当前位置: 首页>>代码示例>>C#>>正文


C# Texture2D.GetLength方法代码示例

本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.Texture2D.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.GetLength方法的具体用法?C# Texture2D.GetLength怎么用?C# Texture2D.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Xna.Framework.Graphics.Texture2D的用法示例。


在下文中一共展示了Texture2D.GetLength方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValiderDimensionsDeTextures

 /// <summary>
 /// Cette fonction s'assure que les textures contenues dans le tableau de
 /// textures fourni en argument (paramètre tex) aient toutes les mêmes
 /// dimensions. Si ce n'est pas le cas, une exception est lancée.
 /// </summary>
 /// <param name="tex">Tableau des textures à valider.</param>
 private static void ValiderDimensionsDeTextures(Texture2D[,] tex)
 {
     // On s'assure que toutes les images ont les mêmes dimensions.
     int largeur = tex[0, 0].Width;
     int hauteur = tex[0, 0].Height;
     for (int row = 0; row < tex.GetLength(0); row++)
     {
         for (int col = 0; col < tex.GetLength(1); col++)
         {
             if (tex[row, col].Width != largeur || tex[row, col].Height != hauteur)
             {
                 throw new System.Exception("les images doivent être de dimensions uniformes");
             }
         }
     }
 }
开发者ID:aggrenier,项目名称:PepinAventure,代码行数:22,代码来源:MondeImages.cs

示例2: LoadContent

        public override void LoadContent()
        {
            // Load Entities
            sprEntities = new Dictionary<EntitySpriteId, Sprite>();
            sprEntities.Add(EntitySpriteId.Warrior, new Sprite(Content, "Warrior").loadSpriteParts(SpriteParts.Entity));
            sprEntities.Add(EntitySpriteId.Warlock, new Sprite(Content, "Warlock").loadSpriteParts(SpriteParts.Entity));
            sprEntities.Add(EntitySpriteId.Wraith, new Sprite(Content, "Wraith").loadSpriteParts(SpriteParts.Entity));
            sprEntities.Add(EntitySpriteId.Skeleton_King, new Sprite(Content, "Skeleton_King").loadSpriteParts(SpriteParts.Entity));

            // Load Attacks
            sprAttacks = new Dictionary<AttackSpriteId, Texture2D>();
            sprAttacks.Add(AttackSpriteId.Fireball, Content.Load<Texture2D>("Fireball/Fireball"));
            sprAttacks.Add(AttackSpriteId.Iceball, Content.Load<Texture2D>("Iceball/Iceball"));
            sprAttacks.Add(AttackSpriteId.Scurge_Shot, Content.Load<Texture2D>("Scurge_Shot/Scurge_Shot"));
            sprAttacks.Add(AttackSpriteId.Raise_Death, Content.Load<Texture2D>("Raise_Death/Raise_Death"));

            // Load Terrain
            Texture2D TerrainSpriteSheet = Content.Load<Texture2D>("Terrain/Terrain");
            Texture2D[] TerrainTexs = new Texture2D[TerrainSpriteSheet.Width / TileMap.SPRITE_SIZE];
            for (int i=0; i<TerrainTexs.Length; i++) TerrainTexs[i] = Helper.ParseSpriteSheet(TerrainSpriteSheet, i, TileMap.SPRITE_SIZE);
            sprTerrains = new Dictionary<TerrainSpriteId, Texture2D>();
            sprTerrains.Add(TerrainSpriteId.None, null);
            sprTerrains.Add(TerrainSpriteId.Stone_Wall, TerrainTexs[0]);
            sprTerrains.Add(TerrainSpriteId.Stone2_Wall, TerrainTexs[1]);
            sprTerrains.Add(TerrainSpriteId.Door, TerrainTexs[2]);
            sprTerrains.Add(TerrainSpriteId.EmptyMagicWall, TerrainTexs[7]);
            sprTerrains.Add(TerrainSpriteId.ClosedChest, TerrainTexs[8]);
            sprTerrains.Add(TerrainSpriteId.OpenChest, TerrainTexs[9]);
            sprTerrains.Add(TerrainSpriteId.IronDoor, TerrainTexs[10]);

            Animations = new Dictionary<Animation,Sprite>();
            Animations.Add(Animation.RedSpiral, new Sprite(new Texture2D[] {TerrainTexs[3],TerrainTexs[4],TerrainTexs[5],TerrainTexs[6]}, 4, 100));

            // Load GUI
            sprGUI = new Dictionary<GUISpriteId, Texture2D>();
            sprGUI.Add(GUISpriteId.Blocking, Content.Load<Texture2D>("GUI/Blocking"));
            sprGUI.Add(GUISpriteId.Ducking, Content.Load<Texture2D>("GUI/Crouching"));
            sprGUI.Add(GUISpriteId.Standing, Content.Load<Texture2D>("GUI/Standing"));

            // Load Backgrounds
            Backgrounds = new Dictionary<BackgroundId,Texture2D>();
            Backgrounds.Add(BackgroundId.Cave1, Content.Load<Texture2D>("Terrain/cave1_background"));

            // Load Items
            Texture2D ItemSpriteSheet = Content.Load<Texture2D>("Items/Items");
            Texture2D[] ItemTexs = new Texture2D[ItemSpriteSheet.Width / Item.SIZE];
            for (int i=0; i<ItemTexs.Length; i++) ItemTexs[i] = Helper.ParseSpriteSheet(ItemSpriteSheet, i, Item.SIZE);
            Items = new Dictionary<ItemId, Item>();
            Items.Add(ItemId.None, null);
            Items.Add(ItemId.Key, new Item(ItemId.Key, "Door Key", ItemTexs[0], Item.NewRoom));
            Items.Add(ItemId.SmallPotion, new Item(ItemId.SmallPotion, "Small Potion", ItemTexs[1], Item.UseSmallPotion));
            Items.Add(ItemId.Gold, new Item(ItemId.Gold, "Gold", ItemTexs[2], Item.NoAction, true));

            // Load Armour
            Texture2D ArmourSpriteSheet = Content.Load<Texture2D>("Armour/Armour");
            Texture2D[,] ArmourTexs = new Texture2D[ArmourSpriteSheet.Height / TileMap.SPRITE_SIZE, ArmourSpriteSheet.Width / TileMap.SPRITE_SIZE];
            for (int h = 0; h < ArmourTexs.GetLength(0); h++)
                for (int w = 0; w < ArmourTexs.GetLength(1); w++)
                    ArmourTexs[h, w] = Helper.ParseSpriteSheet(ArmourSpriteSheet, w, h, TileMap.SPRITE_SIZE);
            Armours = new Dictionary<ItemId, Armour>();
            Armours.Add(ItemId.BronzeHead, new Armour(ArmourTexs[0, 0], ArmourTexs[0, 3], "Bronze Helm", ItemId.BronzeHead, ArmourParts.Head, 0.075f, true));
            Armours.Add(ItemId.BronzeBody, new Armour(ArmourTexs[0, 1], ArmourTexs[0, 4], "Bronze Body", ItemId.BronzeBody, ArmourParts.Body, 0.075f, true));
            Armours.Add(ItemId.BronzeLegs, new Armour(ArmourTexs[0, 2], ArmourTexs[0, 5], "Bronze Legs", ItemId.BronzeLegs, ArmourParts.Legs, 0.075f, true));
            Armours.Add(ItemId.IronHead, new Armour(ArmourTexs[1, 0], ArmourTexs[1, 3], "Iron Helm", ItemId.IronHead, ArmourParts.Head, 0.150f, true));
            Armours.Add(ItemId.IronBody, new Armour(ArmourTexs[1, 1], ArmourTexs[1, 4], "Iron Body", ItemId.IronBody, ArmourParts.Body, 0.150f, true));
            Armours.Add(ItemId.IronLegs, new Armour(ArmourTexs[1, 2], ArmourTexs[1, 5], "Iron Legs", ItemId.IronLegs, ArmourParts.Legs, 0.150f, true));
        }
开发者ID:abenavente406,项目名称:RPG,代码行数:67,代码来源:GameScreen.cs

示例3: MergeTextures

        /// <summary>
        /// Merges textures together to a big texture.
        /// </summary>
        /// <param name="toMerge">The textures to merge, THEY MUST BE THE SAME SIZE.</param>
        /// <returns>The new texture</returns>
        public Texture2D MergeTextures(Texture2D[,] toMerge)
        {
            int targetWidth = 0;
            int targetHeight = 0;

            // Check if we can merge the new texture; if the sizes aren't equal, we cant do it, for now
            foreach (Texture2D tex in toMerge)
            {
                if (toMerge[0, 0].Width != tex.Width || toMerge[0, 0].Height != tex.Height)
                {
                    throw new Exception("Texture sizes aren't equal; cannot merge!");
                }
            }

            int textureWidth = toMerge[0, 0].Width;
            int textureHeight = toMerge[0, 0].Height;

            targetWidth = toMerge[0, 0].Width * toMerge.GetLength(0);
            targetHeight = toMerge[0, 0].Height * toMerge.GetLength(1);

            int[] result = new int[targetWidth * targetHeight];
            for (int i = 0; i < toMerge.GetLength(0); i++)
            {
                for (int j = 0; j < toMerge.GetLength(1); j++)
                {
                    int[] tempData = new int[toMerge[i, j].Width * toMerge[i, j].Height];
                    toMerge[i, j].GetData(tempData);

                    for (int k = 0; k < tempData.Length; k++)
                    {
                        // if tempData[k] == 0, it will bring row from -1 to 0
                        int xoffset = k % textureWidth;
                        int startPoint = (j * toMerge[i, j].Height * targetWidth) + i * toMerge[i, j].Width;
                        int yoffset = (k / textureWidth) * targetWidth;

                        result[startPoint + xoffset + yoffset] = tempData[k];
                    }
                    if (onLoadTickListeners != null) onLoadTickListeners(this);
                }
            }

            Texture2D resultTex = new Texture2D(Game1.GetInstance().graphics.GraphicsDevice, targetWidth, targetHeight);
            resultTex.SetData(result);
            return resultTex;
        }
开发者ID:Wotuu,项目名称:RTS_XNA_v2,代码行数:50,代码来源:MiniMap.cs


注:本文中的Microsoft.Xna.Framework.Graphics.Texture2D.GetLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。