Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to animate my object according to a set of recorded values from kinect skeleton stream by saving the (x,y,z) stream from the skeletal data into a list and then set my objects x and y position from the x,y of the list. However, once the list end has been reached it starts to animate again from the start. I don't want that - I just want the model position to keep going in the positive X direction. Is there any way I can check if end of the list has been reached and to just update the model position in x direction?

Or is there any other way to continue moving my sprite once the points in the list are over... i dont want it to start animating all the way again..

   protected override void Update(GameTime gameTime)

            //position += spriteSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;

            //// TODO: Add your update logic here
            using (StreamReader r = new StreamReader(f))
                string line;
                Viewport view = graphics.GraphicsDevice.Viewport;
                int maxWidth = view.Width;
                int maxHeight = view.Height;

                while((line = r.ReadLine()) != null)

                    string[] temp = line.Split(',');

                    int x = (int) Math.Floor(((float.Parse(temp[0]) * 0.5f) + 0.5f) * maxWidth);
                    int y = (int) Math.Floor(((float.Parse(temp[1]) * -0.5f) + 0.5f) * maxHeight);

                    motion_2.Add(new Point(x, y));  


                position.X = motion_2[i].X;
                position.Y = motion_2[i].Y;





share|improve this question
What is 'f' which you are using as a parameter to your StreamReader? Is there any length parameter for 'f', if not, could you check the length in advance? – zehelvion Oct 5 '12 at 15:24
f is just storing a string file path . . for the stream reader to read from . . – Sweta Dwivedi Oct 5 '12 at 15:29

Problem solved. . . I have used int count; instead of i in the above code

        if (++count >= motion_2.Count)

            if (position.X < -200)
                count = 0;

            float x = (float)((motion_2[count].X * 0.5f) + 0.5f) * maxX);
            float y = (float)(((motion_2[count].Y * -0.5f) + 0.5f) * maxY);

            position.X = x;
            position.Y = y;
            scale = (float)motion_2[count].Z;

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.