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;
     }
                                        }

                                    }
                                }
                            }
                        }                             

Recommended Answers

All 4 Replies

I expect this was intending to be a code snippet and not a question?

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

When adding a new article, change the discussion type to code snippet :)

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;
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.