   [XNA] Sprite Play Through
  Hello, I am pretty new to programming C# and I have got my code to work to a point but I cannot seem to get this to work to my knowledge without using a timer (which would not be consistent for every sprite I want to play)What is happening is, the sprite only plays WHILE the button is being held down.  I want all of the sprite frames to play through once and then stop, when the button is pressed.All of this code works, but just looping the sprite.I am using this to load the sprite:  highPunch = new UserControlledSprite(  Game.Content.Load<Texture2D>(@"Images/highPunch"), Vector2.Zero, new Point(200, 200), 10, new Point(0, 900), new Point(9, 1), new Vector2(6, 6));I am using this code for input:  if (Keyboard.GetState().IsKeyDown(Keys.F))  { inputAccept = true; isHighPunching = true;  }Then it should play the animation with this:if (inputAccept == true)  { if (isHighPunching) {player = highPunch; }}I am aware that it is probably due to the way that the inputs are being accepted, or the if statement only being true while the button is held down.But I cannot find anything on it, I have checked a ton of resources and they all teach this same way.  But none of them show you how to play through all the frames of a sprite after a button is pressed.Can someone please show me where to go from here, or how to set it up to run all the way through and not just while the button is held?Any help is appreciated.   
  First of all, to get better (and more) responses you should, in the future, name yr topics more descriptively.  Yr topic should be something like: "[XNA] Playing an Animation Sequence".Secondly, here is my advice.  Please note that it is a method that I have employed, but it may or may not be the most effective solution, but it is a solution.Thirdly, so that we are on the same page, I will enumerate yr goals as I interpreted them:1. You want to play an x - frame 2D animation sequence where x is the number of frames in the sequence.2. You want the sequence to begin when a key -- in this case, the 'F' key -- is pressed.There are two methods that I would employ based on how you are regulating yr frame rate.  Frame rates are usually regulated either by limiting the frame rate via timers or by implementing a frame rate independent movement scheme.  I will assume the former in this case; however the latter case will involve some slight changes.Here is some pseudo-code to illustrate how yr goals might be accomplished:unsigned int numFRAMES_in_SEQUENCE = x;   // This is how many frames that   // are in the animation sequence.unsigned int highPunchCounter = 0;   // The counter for which frame in the   // sequence that we're on.bool isHighPunching = false;    // Initialize to false.unsigned int numFRAMES_per_SEQ_FRAME = y; // The number of frames for which to  // display a single frame in the  // animation sequence.  This so the   // animation sequence is slow enough  // for the player to observe.  // For slower animations,   // set y higher.unsigned int SEQ_FRAME_Counter  = 0; // Counter to keep track of how many  // frames the current animation frame  // has been displayed.// You have some game loopLoop{// get inputif (Keyboard.GetState().IsKeyDown(Keys.F) && highPunchCounter == 0 ){isHighPunching = true; // only start the animation sequence if the   // user presses the 'F' key and the sequence   // is currently NOT running.}// do animation sequence operations:if ( isHighPunching ) // only do sequence if player is high punching!{SEQ_FRAME_Counter++;  // increment sequence frame counter.if ( SEQ_FRAME_Counter >= numFRAMES_per_SEQ_FRAME ){highPunchCounter++;// increment the animation frame.SEQ_FRAME_Counter = 0;  // reset frame counter.}if ( highPunchCounter >= numFRAMES_in_SEQUENCE ){if ( SEQ_FRAME_Counter >= numFRAMES_per_SEQ_FRAME ){// reset everything; animation sequence is complete.highPunchCounter  = 0;isHighPunching    = false;SEQ_FRAME_Counter = 0;// animation sequence is now ready to begin again// as soon as player initializes sequence again// with appropriate button press. ( 'F' key ).}}}blit( player, highPunchCounter );  // Blit the player to the screen, using// the animation frame highPunchCounter.  }Basically, you only allow the sequence to begin if and only if the player presses the appropriate button and the highPunchCounter == 0 ( at the beginning of the high punching animation sequence.  Once initiated, you now have its choreography automated; it must complete before the player can initiate the high punching sequence again.Hopefully I have explained this clearly.   ;  This is helpful, thank you.With this in mind, do you think it would be easier to just use single .pngs as frames and load them into an array as opposed to going through all of the effort to place them perfectly in a line in a single png, then split them up with code and insert them into an array?That is the way I am doing it now. (the single .png with all frames) because I was told that it is a better practice, and more efficient on the machine, but it seems like awful waste of time to me.Again, thank you for the info.   ;Quote:Original post by duder673This is helpful, thank you.With this in mind, do you think it would be easier to just use single .pngs as frames and load them into an array as opposed to going through all of the effort to place them perfectly in a line in a single png, then split them up with code and insert them into an array?I always use sprite sheets; I think they are easier.  If all yr animation frames are the same size and you group like animations together in rows then it is very easy to blit whatever frame you need.Quote:Original post by duder673That is the way I am doing it now. (the single .png with all frames) because I was told that it is a better practice, and more efficient on the machine, but it seems like awful waste of time to me.Again, thank you for the info.I think it is less of a headache.  What happens if you have 32417891847 frames of animation?  Are you going to load all these individual files or just a few sprite sheets?There are automated methods in which to assemble the sprite sheet in an orderly fashion.  So if you have a collection of .pngs and you are manually copy-n-pasting into a sprite sheet it can be a pain, but as I said there are automated methods.One that I use is discussed here.  Lol, I still keep that page bookmarked.;  Yes, there is also a sprite sheet creator here:http://www.ziggyware.com/readarticle.php?article_id=283But I do not know how to use it, that site is broken and won't allow me to register (a server email error comes up every time), so I can't ask questions either.Yeah I agree that it will would help you organize better, but in terms of time of development, I think it would take longer.  I guess it is just preference.   