Jump to content
  • 0

Adding Frames


Ainz Ooal Gown

Question

Hi All,

 

I have been messing around with the source to try and add additional frames for sprites. Bare with me as I am new to C# and the source so a bit of a noob.

 

I have managed to add 8 frames for sprite movement, but I am unsure to how to centralise the sprite. At the moment it is off to the left and I cant see where I would make it so its in the center of the entity.

 

With JCs edit with _idle _attack and such I have made the base sprite purly walking animations and used the _idle for the sprite not moving at all and changed "TimeBeforeIdling = 50;" so as soon as the player stops moving it plays idle. I might be going around this the wrong way so any advice will be helpful.

 

Made a gif of issue:

 

Spoiler

5b46a68994c03cc619d496a3d18ea35f.gif

 

I thought it would have been this:


 

        protected virtual void CalculateCenterPos()
        {
            var pos = new Pointf(
                LatestMap.GetX() + X * Options.TileWidth + OffsetX + Options.TileWidth / 2,
                LatestMap.GetY() + Y * Options.TileHeight + OffsetY + Options.TileHeight / 2
            );

            if (Texture != null)
            {
                pos.Y += Options.TileHeight / 2;
                pos.Y -= Texture.GetHeight() / 8;
            }

            mCenterPos = pos;

 

and changing line

LatestMap.GetX() + X * Options.TileWidth + OffsetX + Options.TileWidth / 2,

to

LatestMap.GetX() + X * Options.TileWidth + OffsetX + Options.TileWidth / 4,

 

But above didnt work.

 

Thanks

Link to comment
Share on other sites

16 answers to this question

Recommended Posts

  • 0

You have to change destRectangle.X value on the Draw method in Client.Entities.Entity

Change this line

destRectangle.X -= texture.GetWidth() / 8

to

destRectangle.X -= (number of horizontal frames * 2);

destRectangle.X -= texture.GetWidth() / (number of horizontal frames * 2);

 

And be sure everywhere there is texture.GetWidth() / 4 or texture.GetHeight() / 4, you divide it by the number of horizontal and vertical frames you have.

But if instead of texture.GetWidth() / 4 it's texture.GetWidth() / 8, then it's the number of frames * 2 you have to put instead of 8.

 

Your game looks cool

Link to comment
Share on other sites

  • 0
21 minutes ago, Shenmue said:

Change this line

destRectangle.X -= texture.GetWidth() / 8

to

destRectangle.X -= (number of horizontal frames * 2);

I did an error bro,

 

Change this line

destRectangle.X -= texture.GetWidth() / 8

to

destRectangle.X -= texture.GetWidth() / (number of horizontal frames * 2);

Link to comment
Share on other sites

  • 0

oo nice we are using the same assets xD

that can be fixed in the Client/Entity.cs/CalculateCenterPos

                pos.Y += Options.TileHeight / 2;
                pos.Y -= Texture.GetHeight() / (VerticalSpriteFrames * 2);

where VerticalSpriteFrames is the amount of vertical frames, depends if you are using 8x4 or 8x8 sheets

also you are better off changing all the "Texture.GetWidth/GetHeight / 4" in the code to match your sheets

Link to comment
Share on other sites

  • 0
14 minutes ago, Shenmue said:

I did an error bro,

 

Change this line

destRectangle.X -= texture.GetWidth() / 8

to

destRectangle.X -= texture.GetWidth() / (number of horizontal frames * 2);

 

Thanks again it did make the sprite central, but the target and sprite box is will off. I think I did this a pure lazy way after reading what you said.

 

Basically all I did was replace the "texture.GetWidth() / 4" to "texture.GetWidth() / 8"

 

I didnt touch the height ones as they are still 4 frames high...

 

Example:

 

                                3 * (int)texture.GetWidth() / 8, d * (int)texture.GetHeight() / 4,
                                (int)texture.GetWidth() / 8, (int)texture.GetHeight() / 4

 

Im not the best coder, and havent really coded anything in a long time :(

 

4 minutes ago, gooby said:

oo nice we are using the same assets xD

that can be fixed in the Client/Entity.cs/CalculateCenterPos


                pos.Y += Options.TileHeight / 2;
                pos.Y -= Texture.GetHeight() / (VerticalSpriteFrames * 2);

where VerticalSpriteFrames is the amount of vertical frames, depends if you are using 8x4 or 8x8 sheets

also you are better off changing all the "Texture.GetWidth/GetHeight / 4" in the code to match your sheets

 

Thats all I did really mate was change the texture.GetWidth() / 4 to 8

 

Sprites Im using are 8width by 4height

Link to comment
Share on other sites

  • 0
2 minutes ago, Ainz Ooal Gown said:

 

Thanks again it did make the sprite central, but the target and sprite box is will off. I think I did this a pure lazy way after reading what you said.

 

Basically all I did was replace the "texture.GetWidth() / 4" to "texture.GetWidth() / 8"

 

I didnt touch the height ones as they are still 4 frames high...

 

Example:

 

                                3 * (int)texture.GetWidth() / 8, d * (int)texture.GetHeight() / 4,
                                (int)texture.GetWidth() / 8, (int)texture.GetHeight() / 4

 

Im not the best coder, and havent really coded anything in a long time :(

Well you did what was suggering to do. I guess the issue is somehow related to srcRectangle or destRectangle. Good luck mate

Link to comment
Share on other sites

  • 0

Thanks both @Shenmue and @gooby for help, issue is resolved :)

 

Changed:

 

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

to

destRectangle.X -= texture.GetWidth() / (8*2);

 

Didnt need to multiply the "texture.GetWidth() / 8," it seems fine without multipling it by 2.

 

Thanks again :D

Link to comment
Share on other sites

  • 0

Hey I'm using the same graphics as you are and added the 8 frames of movement as well. I ended up just changing it to 16 and is working great.

 

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

 

Link to comment
Share on other sites

  • 0
8 minutes ago, Justn said:

Hey I'm using the same graphics as you are and added the 8 frames of movement as well. I ended up just changing it to 16 and is working great.

 

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

 

 

Yeah suppose that would work aswell as 8*2 is 16. Nice one buddy.

Link to comment
Share on other sites

  • 0

Also to fix the admin panel (insert) I had to change this line:

 SpritePanel.SetUv(0, 0, .25f, .25f);

 

to

 

 SpritePanel.SetUv(0, 0, .125f, .25f);

 

in case you run into that issue.

Link to comment
Share on other sites

  • 0
2 minutes ago, Justn said:

Also to fix the admin panel (insert) I had to change this line:

 SpritePanel.SetUv(0, 0, .25f, .25f);

 

to

 

 SpritePanel.SetUv(0, 0, .125f, .25f);

 

in case you run into that issue.

 

Ah thanks, where abouts is that located and what does it fix?

Link to comment
Share on other sites

  • 0
1 minute ago, Ainz Ooal Gown said:

 

Ah thanks, where abouts is that located and what does it fix?

Ah sorry

 

Located in AdminWindow.cs  line 275.

Just fixes the preview window when changing your sprite via the Admin Window. It was just one of those weird edits that didn't involve just changing "/ 4 to "/8" lol

Link to comment
Share on other sites

  • 0
Just now, Justn said:

Ah sorry

 

Located in AdminWindow.cs  line 275.

Just fixes the preview window when changing your sprite via the Admin Window. It was just one of those weird edits that didn't involve just changing "/ 4 to "/8" lol

 

Awesome mate thanks alot :)

Link to comment
Share on other sites

  • 0
12 minutes ago, Justn said:

Ah sorry

 

Located in AdminWindow.cs  line 275.

Just fixes the preview window when changing your sprite via the Admin Window. It was just one of those weird edits that didn't involve just changing "/ 4 to "/8" lol

 

Do you know what handles the draw of player image in top right next to hp, name, lvl and that?

Link to comment
Share on other sites

  • 0
17 minutes ago, Ainz Ooal Gown said:

 

Do you know what handles the draw of player image in top right next to hp, name, lvl and that?

I think it is this. 

 

EntityBox.cs lines 722 794 and 800 and change the widths to 8's

 

Line 722 = EntityFace.SetTextureRect(0, 0, entityTex.GetWidth() / 4, entityTex.GetHeight() / 4);

Link to comment
Share on other sites

  • 0
4 minutes ago, Justn said:

I think it is this. 

 

EntityBox.cs lines 722 794 and 800 and change the widths to 8's

 

Line 722 = EntityFace.SetTextureRect(0, 0, entityTex.GetWidth() / 4, entityTex.GetHeight() / 4);

 

Nice one buddy thanks again :)

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...