[C#][XNA] AnimatedTexture Class

Discussion in 'Programming General' started by Blupig, Jul 21, 2013.

[C#][XNA] AnimatedTexture Class
  1. Unread #1 - Jul 21, 2013 at 2:26 AM
  2. Blupig
    Joined:
    Nov 23, 2006
    Posts:
    7,145
    Referrals:
    16
    Sythe Gold:
    1,609
    Discord Unique ID:
    178533992981594112
    Valentine's Singing Competition Winner Member of the Month Winner MushyMuncher Gohan has AIDS Extreme Homosex World War 3 I'm LAAAAAAAME
    Off Topic Participant

    Blupig BEEF TOILET
    $5 USD Donor

    [C#][XNA] AnimatedTexture Class

    Hi doods. I'm making a game and I just finished my AnimatedTexture class.

    DON'T NAIL ME FOR HOW IT'S WRITTEN, IT'S 2AM AND I'M TIRED. It works for me the way it is, make improvements if you want to.

    Give credit if you use it! This is my original code.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework.Content;
    
    namespace Game2D
    {
        public class AnimatedTexture
        {
    
            public Rectangle FrameSize;
            private Texture2D sheet;
            private int counter = 0;
    
            public Vector2 Position = Vector2.Zero;
    
            public void LoadContent(ContentManager contentManager, string SheetAssetName)
            {
                sheet = contentManager.Load<Texture2D>(SheetAssetName);
            }
    
            public void DrawFrame(SpriteBatch spriteBatch, int frameNumber)
            {
                spriteBatch.Draw(sheet, Position, new Rectangle(FrameSize.Width * frameNumber, FrameSize.Y, FrameSize.Width, FrameSize.Height), Color.White);
            }
    
            public void DrawAnim(SpriteBatch spriteBatch, int countermax)
            {
    
                if (FrameSize.X <= sheet.Width)
                {
                    if (counter == countermax)
                    {
                        spriteBatch.Draw(sheet, Position, FrameSize, Color.White);
                        FrameSize.X += FrameSize.Width;
                        counter = 0;
                    }
                    else
                    {
                        spriteBatch.Draw(sheet, Position, FrameSize, Color.White);
                        counter++;
                    }
                }
                else
                {
                    FrameSize.X = 0;
                }
                          
            }
    
    
    
        }
    }
    
    How to use it
    AnimatedTexture.FrameSize
    AnimatedTexture.Position
    AnimatedTexture.LoadContent(ContentManager, SheetAssetName)
    AnimatedTexture.DrawFrame(SpriteBatch, FrameNumber)
    AnimatedTexture.DrawAnim(SpriteBatch, CounterMax)
    If you have any questions PM me.
     
  3. Unread #2 - Aug 26, 2013 at 6:47 AM
  4. Shaaaaun
    Joined:
    Jul 30, 2011
    Posts:
    1,206
    Referrals:
    0
    Sythe Gold:
    1
    Discord Unique ID:
    shaun#4087
    Discord Username:
    shaaaaun

    Shaaaaun Guru
    $25 USD Donor New

    [C#][XNA] AnimatedTexture Class

    Source?
     
  5. Unread #3 - Aug 28, 2013 at 8:43 PM
  6. Blupig
    Joined:
    Nov 23, 2006
    Posts:
    7,145
    Referrals:
    16
    Sythe Gold:
    1,609
    Discord Unique ID:
    178533992981594112
    Valentine's Singing Competition Winner Member of the Month Winner MushyMuncher Gohan has AIDS Extreme Homosex World War 3 I'm LAAAAAAAME
    Off Topic Participant

    Blupig BEEF TOILET
    $5 USD Donor

    [C#][XNA] AnimatedTexture Class

    Reported, I coded this myself.
     
  7. Unread #4 - Aug 29, 2013 at 8:57 AM
  8. Ryan
    Joined:
    Mar 14, 2006
    Posts:
    2,946
    Referrals:
    31
    Sythe Gold:
    56

    Ryan Hopeless Romantic
    Banned

    [C#][XNA] AnimatedTexture Class

    Looks pretty good, what type of game are you making?
     
< Looking for Someone Who Can Script | Programming Question >

Users viewing this thread
1 guest


 
 
Adblock breaks this site