8 Replies - 1335 Views - Last Post: 18 September 2012 - 10:29 AM

#1 hardyyanto  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 30
  • Joined: 12-December 08

how to make animation have one times looping?

Posted 30 August 2012 - 07:45 AM

i have character that doing kick animation..
this animation consist 7 picture..
my code for the animation at the game1.cs page:
 protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //load char
            Animation ca = new Animation();
            Texture2D ct = Content.Load<Texture2D>("fighter");
            ca.initial(ct, Vector2.Zero, 120, 130, 1, 100, Color.White, 1f, true);

            Vector2 cp = new Vector2(GraphicsDevice.Viewport.TitleSafeArea.X, GraphicsDevice.Viewport.TitleSafeArea.Y
                + GraphicsDevice.Viewport.TitleSafeArea.Height / 2);

           cp = new Vector2(300, 300);
            character.initialize(ca, cp);
}

  private void updateplayer(GameTime gt)
  if (currentks.IsKeyDown(Keys.RightShift))
            {
                Animation ca = new Animation();
                Texture2D ct = Content.Load<Texture2D>("fighter");
                ca.initial(ct, Vector2.Zero, 120, 130, 7, 100, Color.White, 1f, true);

               Vector2 cp = new Vector2(GraphicsDevice.Viewport.TitleSafeArea.X, GraphicsDevice.Viewport.TitleSafeArea.Y
                   + GraphicsDevice.Viewport.TitleSafeArea.Height / 2);

               
               character.initialize(ca, cp);
                         
                            }
           



from this code..
ca.initial(ct, Vector2.Zero, 120, 130, 7, 100, Color.White, 1f, true);
120 is animation width
130 is animation height
7 is total picture in animation that will be looping
100 is speed looping

it's looping continues.. so if i click right shift, the character continues kick, not stop..
how to make that looping only one times..
thanks..

Is This A Good Question/Topic? 0
  • +

Replies To: how to make animation have one times looping?

#2 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: how to make animation have one times looping?

Posted 30 August 2012 - 07:51 AM

You should be able to check what the current animation is, and if you hit the last frame of a non-looping animation, such as your kick, change the animation back to an idle animation, or any other animation.
Was This Post Helpful? 0
  • +
  • -

#3 hardyyanto  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 30
  • Joined: 12-December 08

Re: how to make animation have one times looping?

Posted 30 August 2012 - 08:37 AM

View PostKilorn, on 30 August 2012 - 07:51 AM, said:

You should be able to check what the current animation is, and if you hit the last frame of a non-looping animation, such as your kick, change the animation back to an idle animation, or any other animation.


no, i don't know how to get that frame value..
can u show me how to get that frame value?
tq..
Was This Post Helpful? 0
  • +
  • -

#4 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: how to make animation have one times looping?

Posted 30 August 2012 - 08:43 AM

I think you need to do a little more research on frame animation. I'd suggest starting by reading through my Animated Sprite tutorial, or SixOfEleven's animation tutorial on this site. This will give you a firm understanding of how frame by frame animations are handled in XNA. Once you have a firm understanding of how frame by frame animations are handled, you'll be able to imagine how you could create multiple animations, and check the current frame of the current animation and know when to change the animation that is currently playing.

This post has been edited by Kilorn: 30 August 2012 - 08:44 AM

Was This Post Helpful? 0
  • +
  • -

#5 hardyyanto  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 30
  • Joined: 12-December 08

Re: how to make animation have one times looping?

Posted 30 August 2012 - 09:17 AM

View PostKilorn, on 30 August 2012 - 08:43 AM, said:

I think you need to do a little more research on frame animation. I'd suggest starting by reading through my Animated Sprite tutorial, or SixOfEleven's animation tutorial on this site. This will give you a firm understanding of how frame by frame animations are handled in XNA. Once you have a firm understanding of how frame by frame animations are handled, you'll be able to imagine how you could create multiple animations, and check the current frame of the current animation and know when to change the animation that is currently playing.


do u mean this site http://kilorn.wordpr...prite-tutorial/
ok, i will check it..
Was This Post Helpful? 0
  • +
  • -

#6 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: how to make animation have one times looping?

Posted 30 August 2012 - 09:55 AM

Yea, that's the same tutorial that I have posted here on Dream.In.Code, and SixOfEleven has one here as well.
Was This Post Helpful? 0
  • +
  • -

#7 hardyyanto  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 30
  • Joined: 12-December 08

Re: how to make animation have one times looping?

Posted 18 September 2012 - 01:56 AM

View PostKilorn, on 30 August 2012 - 09:55 AM, said:

Yea, that's the same tutorial that I have posted here on Dream.In.Code, and SixOfEleven has one here as well.

i have testing your coding about char animation...

i have add the code to my fighter kick animation..

i am pressing and hold the shift, so the fighter can kick continues until i off the pressing..

but i still can not doing one looping kick..
this is my code:
 if(currentKBState.IsKeyDown(Keys.L))
             {
               loopOnce(1,6);
               currentframe++;
             }

  private void loopOnce(int min, int max)
        {
            if (currentImageIndex > max || currentImageIndex < min) //Checks to see if index out of range of current animation
                currentImageIndex = min; //Starts at the beginning of the animation
            for (int i = min; i < max; i++) //Uses the range to determine when to stop
            { currentImageIndex++; } //Increments index each iteration that passes
        }




but it still not looping 1-6 picture animation..
it only work 1 picture part.

how to make it can move all part picture in one click?
thanks..
Was This Post Helpful? 0
  • +
  • -

#8 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: how to make animation have one times looping?

Posted 18 September 2012 - 06:44 AM

You want to take it out of the for loop. If you're increasing the index inside a for loop, you will be increasing the frame index until i = max, and this will all happen without a Draw call, so you'll never see a change.

You will need to create a method that is called each frame from the Update method that will increase the current frame index if enough time has passed since the last time it was changed. I do this using the interval and timer floats that I have declared in the AnimatedSprite class.
Was This Post Helpful? 0
  • +
  • -

#9 hardyyanto  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 30
  • Joined: 12-December 08

Re: how to make animation have one times looping?

Posted 18 September 2012 - 10:29 AM

View PostKilorn, on 18 September 2012 - 06:44 AM, said:

You want to take it out of the for loop. If you're increasing the index inside a for loop, you will be increasing the frame index until i = max, and this will all happen without a Draw call, so you'll never see a change.

You will need to create a method that is called each frame from the Update method that will increase the current frame index if enough time has passed since the last time it was changed. I do this using the interval and timer floats that I have declared in the AnimatedSprite class.


your coding in animatedsprite for making animation speed..
public void animatekick(GameTime gt)
{
    if(currentKBState !=previousKBState)
    {
        currentframe=0;
    }

    timer += (float)gt.ElapsedGameTime.TotalMilliseconds;

    if (timer > interval)
    {
           
        currentframe++;
                      
        if (currentframe > 6)
        {
            currentframe = 0;
        }
            
        timer = 0f;
    }
}



i think must be using array for looping...

This post has been edited by Kilorn: 18 September 2012 - 11:24 AM
Reason for edit:: Added code tags.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1