Adblock breaks this site

[C#][XNA] AnimatedTexture Class

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

  1. Blupig

    Blupig BEEF TOILET
    $5 USD Donor

    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
    [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.
     
  2. Shaaaaun

    Shaaaaun Guru
    $25 USD Donor New

    Joined:
    Jul 30, 2011
    Posts:
    1,206
    Referrals:
    0
    Sythe Gold:
    1
    Discord Unique ID:
    shaun#4087
    Discord Username:
    shaaaaun
    [C#][XNA] AnimatedTexture Class

    Source?
     
  3. Blupig

    Blupig BEEF TOILET
    $5 USD Donor

    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
    [C#][XNA] AnimatedTexture Class

    Reported, I coded this myself.
     
  4. Ryan

    Ryan Hopeless Romantic
    Banned

    Joined:
    Mar 14, 2006
    Posts:
    2,946
    Referrals:
    31
    Sythe Gold:
    56
    [C#][XNA] AnimatedTexture Class

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


 
 
Adblock breaks this site