コード例 #1
0
ファイル: TextureAtlas.cs プロジェクト: xxami/Pulsus
        /// <summary> Creates an array of sub-textures from texture atlas where sub-images are aligned in a grid pattern</summary>
        /// <param name="texture">Texture atlas</param>
        /// <param name="elementWidth">Width of a single element in the grid</param>
        /// <param name="elementHeight">Height of a single element in the grid</param>
        /// <param name="elementCount">Number of elements in the grid</param>
        public static SubTexture[] CreateFromGrid(Texture2D texture, int elementWidth, int elementHeight, int elementCount)
        {
            if (elementCount <= 0)
            {
                throw new ArgumentOutOfRangeException("Invalid number of elements");
            }

            SubTexture[] subTextures = new SubTexture[elementCount];

            for (int i = 0; i < elementCount; i++)
            {
                int x = (i * elementWidth) % texture.width;
                int y = ((i * elementWidth) / texture.width) * elementHeight;
                subTextures[i] = new SubTexture(texture, new Rectangle(x, y, elementWidth, elementHeight));
            }

            return(subTextures);
        }
コード例 #2
0
 public void Draw(SubTexture subTexture, Rectangle rect, float rotation, Color color)
 {
     spriteBatch.Add(new Sprite(subTexture.texture, new Int2(rect.x, rect.y), new Int2(rect.width, rect.height),
                                rotation, rect.width / 2.0f, rect.height / 2.0f, subTexture.sourceRect, color));
 }
コード例 #3
0
 public void Draw(SubTexture subTexture, Int2 pos, float rotation, Color color)
 {
     spriteBatch.Add(new Sprite(subTexture.texture, pos, new Int2(subTexture.sourceRect.width, subTexture.sourceRect.height),
                                rotation, subTexture.texture.width / 2.0f, subTexture.texture.height / 2.0f, subTexture.sourceRect, color));
 }
コード例 #4
0
 public void Draw(SubTexture subTexture, Int2 pos, Color color)
 {
     spriteBatch.Add(new Sprite(subTexture.texture, pos, new Int2(subTexture.sourceRect.width, subTexture.sourceRect.height),
                                subTexture.sourceRect, color));
 }