Jump to content
  • 0

Animation Frames


corrupted

Question

first sorry for the bad english. I'm using LPC Graphics, I added the 13 side frames and it works perfectly, even the paperdoll works. the problem is that the attack, shoot, cast animations only move 4 frames. the animation when walking works perfectly and the idle too.

Sprite Draw:

Spoiler

if (Options.AnimatedSprites.Contains(sprite.ToLower()))
                {
                    srcRectangle = new FloatRect(
                        AnimationFrame * (int)texture.GetWidth() / 13, d * (int)texture.GetHeight() / 4,
                        (int)texture.GetWidth() / 13, (int)texture.GetHeight() / 4
                    );
                }
                else
                {
                    if (SpriteAnimation == SpriteAnimations.Normal)
                    {
                        var attackTime = CalculateAttackTime();
                        if (AttackTimer - CalculateAttackTime() / 2 > Globals.System.GetTimeMs() || Blocking)
                        {
                            srcRectangle = new FloatRect(
                                3 * (int)texture.GetWidth() / 13, d * (int)texture.GetHeight() / 4,
                                (int)texture.GetWidth() / 13, (int)texture.GetHeight() / 4
                            );
                        }
                        else
                        {
                            //Restore Original Attacking/Blocking Code
                            srcRectangle = new FloatRect(
                                WalkFrame * (int) texture.GetWidth() / 13, d * (int) texture.GetHeight() / 4,
                                (int) texture.GetWidth() / 13, (int) texture.GetHeight() / 4
                            );
                        }
                    }
                    else
                    {
                        srcRectangle = new FloatRect(
                            SpriteFrame * (int)texture.GetWidth() / 13, d * (int)texture.GetHeight() / 4,
                            (int)texture.GetWidth() / 13, (int)texture.GetHeight() / 4
                        );
                    }
                }

 

Other modifications:

Spoiler

destRectangle.X -= texture.GetWidth() / 26;

 if (IsMoving)
                    {
                        WalkFrame++;
                        if (WalkFrame >= 13)
                        {
                            WalkFrame = 0;
                        }
                    }

if (AnimationTimer < Globals.System.GetTimeMs())
            {
                AnimationTimer = Globals.System.GetTimeMs() + 2000;
                AnimationFrame++;
                if (AnimationFrame >= 13)
                {
                    AnimationFrame = 0;
                }
            }


b207b5c8fe30e0d267cd79a71bc207c7.gif

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

In the UpdateSpriteAnimation method, you have to check in the attack and cast code block where there is a value assignation to "SpriteFrame" and replace the "4f" by the number of frames of the animation.

SpriteFrame = (int)Math.Floor((timeIn / (CalculateAttackTime() / 4f)));
SpriteFrame = (int)Math.Floor((timeIn / (duration / 4f)));

I haven't tested, but I think it should work.

Link to comment
Share on other sites

  • 0
2 hours ago, Shenmue said:

In the UpdateSpriteAnimation method, you have to check in the attack and cast code block where there is a value assignation to "SpriteFrame" and replace the "4f" by the number of frames of the animation.


SpriteFrame = (int)Math.Floor((timeIn / (CalculateAttackTime() / 4f)));
SpriteFrame = (int)Math.Floor((timeIn / (duration / 4f)));

I haven't tested, but I think it should work.

 

I edited and it worked, now I have a problem between the shot and "swords", the animation of the shot has 13 frames and the sword animation has 6 frames. The animation of the sword works perfectly, but the shot shows only the 6 frames. this is my code, i don't know what could be going wrong.

Code:

Spoiler

if (AnimatedTextures[SpriteAnimations.Attack] != null)
                {
                    SpriteAnimation = SpriteAnimations.Attack;

                    SpriteFrame = (int)Math.Floor((timeIn / (CalculateAttackTime() / 13f)));
                }

                if (Options.WeaponIndex > -1 && Options.WeaponIndex < Equipment.Length)
                {
                    if (Equipment[Options.WeaponIndex] != Guid.Empty && this != Globals.Me ||
                        MyEquipment[Options.WeaponIndex] < Options.MaxInvItems)
                    {
                        var itemId = Guid.Empty;
                        if (this == Globals.Me)
                        {
                            var slot = MyEquipment[Options.WeaponIndex];
                            if (slot > -1)
                            {
                                itemId = Inventory[slot].ItemId;
                            }
                        }
                        else
                        {
                            itemId = Equipment[Options.WeaponIndex];
                        }

                        var item = ItemBase.Get(itemId);
                        if (item != null)
                        {
                             if (AnimatedTextures[SpriteAnimations.Weapon] != null)
                            {
                                SpriteAnimation = SpriteAnimations.Weapon;
                                SpriteFrame++;
                                if (SpriteFrame >= 6)
                                {
                                    SpriteFrame = 0;
                                }
                                SpriteFrameTimer = Globals.System.GetTimeMs();
                                }


                            if (AnimatedTextures[SpriteAnimations.Shoot] != null && item.ProjectileId != Guid.Empty)
                            {
                                SpriteAnimation = SpriteAnimations.Shoot;
                                SpriteFrame++;
                                if (SpriteFrame >= 13)
                                {
                                    SpriteFrame = 0;
                                }
                                SpriteFrameTimer = Globals.System.GetTimeMs();                  
                            }
                        }
                    }
                }
            }

 

Link to comment
Share on other sites

  • 0
1 minute ago, corrupted said:

 

I edited and it worked, now I have a problem between the shot and "swords", the animation of the shot has 13 frames and the sword animation has 6 frames. The animation of the sword works perfectly, but the shot shows only the 6 frames. this is my code, i don't know what could be going wrong.

 

It's because of this code:

if (SpriteFrame >= 6)
{
   SpriteFrame = 0;
}

You should remplace the 6 by 13.

Link to comment
Share on other sites

  • 0
5 minutes ago, Shenmue said:

 

It's because of this code:


if (SpriteFrame >= 6)
{
   SpriteFrame = 0;
}

You should remplace the 6 by 13.

in my code there is

If (AnimatedTextures [SpriteAnimations.Shoot]! = null && item.ProjectileId! = Guid.Empty)

which is the code for if the player is using a projectile. right? in this case it makes sense to use

if (SpriteFrame> = 13) { SpriteFrame = 0; } because my shot frame has 13 frames.

Link to comment
Share on other sites

  • 0
Just now, corrupted said:

in my code there is if (AnimatedTextures [SpriteAnimations.Shoot]! = null && item.ProjectileId! = Guid.Empty) which is the code for if the player is using a projectile. right? in this case it makes sense to use if (SpriteFrame> = 13) { SpriteFrame = 0; } because my shot frame has 13 frames.

 

Inside the block of "if (AnimatedTextures[SpriteAnimations.Weapon] != null)" you use "if (SpriteFrame >= 6)". But you should use >= 13 instead.

Link to comment
Share on other sites

  • 0
13 minutes ago, Shenmue said:

 

Inside the block of "if (AnimatedTextures[SpriteAnimations.Weapon] != null)" you use "if (SpriteFrame >= 6)". But you should use >= 13 instead.

 

and how do I make my weapon frame have 6 animations and the shoot have 13 animations? I'm not good with C #

Link to comment
Share on other sites

  • 0
8 minutes ago, corrupted said:

 

and how do I make my weapon frame have 6 animations and the shoot have 13 animations? I'm not good with C #

 

Oh I see my bad. So you want the weapon animation to have 6 frames and the shot one 13.

Then you have to add this "&& item.ProjectileId == Guid.Empty" to the weapon condition "if (AnimatedTextures[SpriteAnimations.Weapon] != null)"

 

The final result should be the code below.

if (AnimatedTextures[SpriteAnimations.Weapon] != null && item.ProjectileId == Guid.Empty)

 

Link to comment
Share on other sites

  • 0
51 minutes ago, Shenmue said:

 

Oh I see my bad. So you want the weapon animation to have 6 frames and the shot one 13.

Then you have to add this "&& item.ProjectileId == Guid.Empty" to the weapon condition "if (AnimatedTextures[SpriteAnimations.Weapon] != null)"

 

The final result should be the code below.


if (AnimatedTextures[SpriteAnimations.Weapon] != null && item.ProjectileId == Guid.Empty)

 

after trying a lot I managed the code looks like this:

I simply added
SpriteFrame = (int) Math.Floor ((timeIn / (CalculateAttackTime () / 13f)));
above: SpriteAnimation = SpriteAnimations.Shoot;

Spoiler

if (AnimatedTextures[SpriteAnimations.Attack] != null)
                {
                    SpriteAnimation = SpriteAnimations.Attack;
                    SpriteFrame = (int)Math.Floor((timeIn / (CalculateAttackTime() / 13f)));
                    SpriteAnimation = SpriteAnimations.Attack;
                    SpriteFrame++;
                    if (SpriteFrame >= 6)
                    {
                        SpriteFrame = 0;
                    }
                    SpriteFrameTimer = Globals.System.GetTimeMs();
                }

                if (Options.WeaponIndex > -1 && Options.WeaponIndex < Equipment.Length)
                {
                    if (Equipment[Options.WeaponIndex] != Guid.Empty && this != Globals.Me ||
                        MyEquipment[Options.WeaponIndex] < Options.MaxInvItems)
                    {
                        var itemId = Guid.Empty;
                        if (this == Globals.Me)
                        {
                            var slot = MyEquipment[Options.WeaponIndex];
                            if (slot > -1)
                            {
                                itemId = Inventory[slot].ItemId;
                            }
                        }
                        else
                        {
                            itemId = Equipment[Options.WeaponIndex];
                        }

                        var item = ItemBase.Get(itemId);
                        if (item != null)
                        {
                            if (AnimatedTextures[SpriteAnimations.Weapon] != null)
                            {
                                SpriteAnimation = SpriteAnimations.Weapon;
                                SpriteFrame++;
                                if (SpriteFrame >= 6)
                                {
                                    SpriteFrame = 0;
                                }
                                SpriteFrameTimer = Globals.System.GetTimeMs();
                            }

                            if (AnimatedTextures[SpriteAnimations.Weapon] != null && item.ProjectileId != Guid.Empty)
                            {
                               


                            }
                        }
                    }
                }

 

Link to comment
Share on other sites

  • 0
7 minutes ago, corrupted said:

after trying a lot I managed the code looks like this:
 

  Reveal hidden contents

if (AnimatedTextures[SpriteAnimations.Attack] != null)
                {
                    SpriteAnimation = SpriteAnimations.Attack;
                    SpriteFrame = (int)Math.Floor((timeIn / (CalculateAttackTime() / 13f)));
                    SpriteAnimation = SpriteAnimations.Attack;
                    SpriteFrame++;
                    if (SpriteFrame >= 6)
                    {
                        SpriteFrame = 0;
                    }
                    SpriteFrameTimer = Globals.System.GetTimeMs();
                }

                if (Options.WeaponIndex > -1 && Options.WeaponIndex < Equipment.Length)
                {
                    if (Equipment[Options.WeaponIndex] != Guid.Empty && this != Globals.Me ||
                        MyEquipment[Options.WeaponIndex] < Options.MaxInvItems)
                    {
                        var itemId = Guid.Empty;
                        if (this == Globals.Me)
                        {
                            var slot = MyEquipment[Options.WeaponIndex];
                            if (slot > -1)
                            {
                                itemId = Inventory[slot].ItemId;
                            }
                        }
                        else
                        {
                            itemId = Equipment[Options.WeaponIndex];
                        }

                        var item = ItemBase.Get(itemId);
                        if (item != null)
                        {
                            if (AnimatedTextures[SpriteAnimations.Weapon] != null)
                            {
                                SpriteAnimation = SpriteAnimations.Weapon;
                                SpriteFrame++;
                                if (SpriteFrame >= 6)
                                {
                                    SpriteFrame = 0;
                                }
                                SpriteFrameTimer = Globals.System.GetTimeMs();
                            }

                            if (AnimatedTextures[SpriteAnimations.Weapon] != null && item.ProjectileId != Guid.Empty)
                            {
                                SpriteFrame = (int)Math.Floor((timeIn / (CalculateAttackTime() / 13f)));
                                SpriteAnimation = SpriteAnimations.Shoot;
                            }
                        }
                    }
                }

 

 

Glad to see it now works, but I wonder, have you tried my solution?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...