Rewrote this a few times heres the meat and potatoes. Has a few issues such as flashing when moving in different directions quickly.
Thinking of trying to clamp a few values to try to stop the diagonal movement,flashing and smoothing out the sprite. Something along these lines might update this later.

A Way to animate a sprite

Materials

  • 2d_GameSkeleton
  • GameStateManagement(not necessary)
  • a few minutes.
  • Sprite Sheet Packer

Setup your integer values from sprite sheet packer XML

something like this

int leftx
leftx = coordinate value



// make a rectangle

Rectangle mcsr
mcsr.X = coordinate from xml
mcsr.Y coordinate from xml





if (keyboardState.IsKeyDown(Keys.Left))

{
 movement.X--;
 asprite.SourceRectangle = mcsr;
 while (sum >= 6)
{
 movement.X--;

 asprite.SourceRectangle = new Rectangle(leftx, lefty, width, height);
 sum = 1;

 if (s == true)
 {
   //Incremement timer using paramater
   m_timer += (float)gameTime.ElapsedGameTime.Milliseconds;

  //Check if timer is greater than interval
  if (m_timer > m_interval)
  {

    movement.X--;
    asprite.SourceRectangle = new Rectangle(leftx1, lefty1, width, height);
    //Reset timer
    m_timer = 700f;
    if (keyboardState.IsKeyDown(Keys.Space))
    {
     m_interval = 775;
     playerPosition += movement * 2.7f;
     if (keyboardState.IsKeyUp(Keys.Space))
     {
      m_interval = 775f;
      playerPosition += movement * 1.7f;
     }
                                        }

                                    }
                                }
                            }
                        }                             

yeah i wasnt aware of a code snippet section. Where is code snippet location for future reference?

Edited 4 Years Ago by XEN0: more information

Ok current scenario there is a follow source property. Do i make input class and plug into follow source property?

public void Follow(field<--- class here variable<---- field decleration, float rotationOffset)
        {
            Source = source;
            SourceRotationOffset = rotationOffset;
        }
This article has been dead for over six months. Start a new discussion instead.