tModLoader Need help with sprite animation code

plong

Terrarian
(note: this is the first time I am posting on these forums so I have no idea if this is the correct place)

I have just recently gotten into some basic Terraria modding, and I am trying to make a small mod with a few basic weapons. However, I have absolutely no idea how to code in the animation for them. I have the sprite sheet with all the frames 2 pixels apart, but I don't know how to get the game to actually use it.

Please help
 
(note: this is the first time I am posting on these forums so I have no idea if this is the correct place)

I have just recently gotten into some basic Terraria modding, and I am trying to make a small mod with a few basic weapons. However, I have absolutely no idea how to code in the animation for them. I have the sprite sheet with all the frames 2 pixels apart, but I don't know how to get the game to actually use it.

Please help
It really depends on what you want for animation, though, the pngs themselves will be formatted as you described, but coding is different for each thing. IF you want to see something like a basic item animation, you should check this out. There is also projectile animation, which you can see with this.
 
This worked, kind of I used the animation code and changed it to fit my weapon

public override DrawAnimation GetAnimation()
{
return new DrawAnimationVertical(10, 4);
}
and the item in the inventory is animated, but when I actually swing the weapon the entire sprite sheet is used, and not just any 1 frame.

Thanks for the reply
 
If you want to animate a weapon, you'll have to make the weapon an animated projectile that functions like your weapon. The GetAnimation() is really only for stuff like Souls.
 
It really depends on what you want for animation, though, the pngs themselves will be formatted as you described, but coding is different for each thing. IF you want to see something like a basic item animation, you should check this out. There is also projectile animation, which you can see with this.
if im animating a projectile would this still work if it growes in size for each frame? or would i need to add more than 2 pixels between them
 
For me, I'm trying to animate one of my sprites horizontally instead of vertically. Is it possible? If so, how can I do it?
 
if im animating a projectile would this still work if it growes in size for each frame? or would i need to add more than 2 pixels between them
You should keep the frame size consistent with the largest frame + 2px buffer. That's the easiest way to handle different sizes (imo).
For me, I'm trying to animate one of my sprites horizontally instead of vertically. Is it possible? If so, how can I do it?
Rather than changing the frameY of whatever projectile/npc/tile you want to animate, use the frameX. This is assuming you're doing a custom animation, since vanilla sprites are (mostly? Terraria is inconsistent) vertically sheeted.
 
Rather than changing the frameY of whatever projectile/npc/tile you want to animate, use the frameX. This is assuming you're doing a custom animation, since vanilla sprites are (mostly? Terraria is inconsistent) vertically sheeted.

I could do that, but how? (Note that I'm still new to modding.) I have Main.RegisterItemAnimation(item.type, new DrawAnimationVertical(4, 15)); written down (for the vertical anims), but I never have used FrameY/X before.

How could I use FrameX/Y? (Examples?)
 
Oh, for items? I'm not sure how you'd go about that to be honest, I've only used vertical spritesheets for items. I'd recommend you do the same rather than trying to use a horizontal spritesheet.
For some reason there's no DrawAnimationHorizontal, and that's the only thing I could think of that isn't a massive workaround.
 
I'm trying to animate an ammo in the inventory, I used this code

public override DrawAnimation GetAnimation()
{
return new DrawAnimationVertical(5, 30);
}

But it always gives me this error message:
Error.PNG


What am I doing wrong? How could I fix this?
 
public override void SetStaticDefaults()
{
Main.projFrames[projectile.type] = 6;
if (++projectile.frameCounter >= 7)
{
projectile.frameCounter = 0;
if (++projectile.frame >= 6)
{
projectile.frame = 0;
}
}
}
 
Back
Top Bottom