tModLoader How do I use a custom Spite Sheet?

I'm working on a personal mod and the town Npc I have keeps on bugging out and walking weird. I have a spritesheet but is there any way to assign certain frames to certain actions?
 
Idk if this works with town NPCs but you might want to check out the flutter slime AI, specially the following:

C#:
        public override void FindFrame(int frameHeight) {
            // This makes the sprite flip horizontally in conjunction with the npc.direction.
            npc.spriteDirection = npc.direction;

            // For the most part, our animation matches up with our states.
            if (AI_State == State_Asleep) {
                // npc.frame.Y is the goto way of changing animation frames. npc.frame starts from the top left corner in pixel coordinates, so keep that in mind.
                npc.frame.Y = Frame_Asleep * frameHeight;
            }
            else if (AI_State == State_Notice) {
                // Going from Notice to Asleep makes our npc look like it's crouching to jump.
                if (AI_Timer < 10) {
                    npc.frame.Y = Frame_Notice * frameHeight;
                }
                else {
                    npc.frame.Y = Frame_Asleep * frameHeight;
                }
            }
            else if (AI_State == State_Jump) {
                npc.frame.Y = Frame_Falling * frameHeight;
            }
            else if (AI_State == State_Hover) {
                // Here we have 3 frames that we want to cycle through.
                npc.frameCounter++;
                if (npc.frameCounter < 10) {
                    npc.frame.Y = Frame_Flutter_1 * frameHeight;
                }
                else if (npc.frameCounter < 20) {
                    npc.frame.Y = Frame_Flutter_2 * frameHeight;
                }
                else if (npc.frameCounter < 30) {
                    npc.frame.Y = Frame_Flutter_3 * frameHeight;
                }
                else {
                    npc.frameCounter = 0;
                }
            }
            else if (AI_State == State_Fall) {
                npc.frame.Y = Frame_Falling * frameHeight;
            }
        }

Ofc you would have to add a few numbers, since the standard npc has around 26 sprites.
 
Back
Top Bottom