Standalone [1.3] tModLoader - A Modding API

And this isn't working for switching frame:
Code:
public override void AI()
        {
            frameTime++;
        }
       
        public override void FindFrame(int frameHeight)
        {
            if (frameTime >= 60)
            {
                npc.frame.Y = frameHeight;
            }
            else
            {
                npc.frame.Y = 0;
                frameTime = 0;
            }
        }
 
And this isn't working for switching frame:
Code:
public override void AI()
        {
            frameTime++;
        }
      
        public override void FindFrame(int frameHeight)
        {
            if (frameTime >= 60)
            {
                npc.frame.Y = frameHeight;
            }
            else
            {
                npc.frame.Y = 0;
                frameTime = 0;
            }
        }
Instead of making some frameTime field, you can use the npc.frameCounter field that's reserved specifically for this.
Also, it would be better to increment npc.frameCounter in FindFrame instead of in AI.
Also you don't want to set frameTime to 0 when it isn't 60; otherwise it will always be switching between 1 and 0.
 
Instead of making some frameTime field, you can use the npc.frameCounter field that's reserved specifically for this.
Also, it would be better to increment npc.frameCounter in FindFrame instead of in AI.
Also you don't want to set frameTime to 0 when it isn't 60; otherwise it will always be switching between 1 and 0.
Thanks. Please excuse my brain damage.
[DOUBLEPOST=1448683681,1448683374][/DOUBLEPOST]Did those changes, animation still doesn't work.
Code:
Code:
public override void FindFrame(int frameHeight)
        {
            npc.frameCounter++;
            if (npc.frameCounter >= 60)
            {
                npc.frame.Y = frameHeight;
                npc.frameCounter = 0;
            }
            else
            {
                npc.frame.Y = 0;
            }
        }
Sprite:
Alien49.png
 
Thanks. Please excuse my brain damage.
[DOUBLEPOST=1448683681,1448683374][/DOUBLEPOST]Did those changes, animation still doesn't work.
Code:
Code:
public override void FindFrame(int frameHeight)
        {
            npc.frameCounter++;
            if (npc.frameCounter >= 60)
            {
                npc.frame.Y = frameHeight;
                npc.frameCounter = 0;
            }
            else
            {
                npc.frame.Y = 0;
            }
        }
Sprite:
View attachment 86140
This'll make it so that your sprite flashes to the second frame for one tick and back, restarting the counter. You'd probably want to keep the frame visible for a few seconds.
 
Is this in miliseconds? How would I do a single second?
One second consists of 60 ticks, so:
Code:
npc.frameCounter++;
if (npc.frameCounter == 60)
{
    if(npc.frame.Y == 0)
        npc.frame.Y = frameHeight;
    else
        npc.frame.Y = 0;
    npc.frameCounter = 0;
}
Something like that.

EDIT:
This is really ugly code, btw ;)
 
One second consists of 60 ticks, so:
Code:
npc.frameCounter++;
if (npc.frameCounter == 60)
{
    if(npc.frame.Y == 0)
        npc.frame.Y = frameHeight;
    else
        npc.frame.Y = 0;
    npc.frameCounter = 0;
}
Something like that.

EDIT:
This is really ugly code, btw ;)
Same result as mine.
 
Same result as mine.
Hmmm allright, lemme try something else (and hope that that works?):
Code:
npc.frameCounter += 0.1F;
npc.frameCounter %= Main.npcFrameCount[npc.type];
int frame = (int)npc.frameCounter;
npc.frame.Y = frame * frameHeight;
 
Hmmm allright, lemme try something else (and hope that that works?):
Code:
npc.frameCounter += 0.1F;
npc.frameCounter %= Main.npcFrameCount[npc.type];
int frame = (int)npc.frameCounter;
npc.frame.Y = frame * frameHeight;
It kinda works. It bobs up and down.
 
It kinda works. It bobs up and down.
The bobbing up and down is because of a... sorry to be rude, but wrongly made spritesheet. With a spritesheet you've got to make sure the paddings are the same for each frame (take the largest frame you have and build from there). I've revised it to work for now:
KWMUvBD.png
 
The bobbing up and down is because of a... sorry to be rude, but wrongly made spritesheet. With a spritesheet you've got to make sure the paddings are the same for each frame (take the largest frame you have and build from there). I've revised it to work for now:
KWMUvBD.png
So, what is the difference between this one and the old one?
 
So, what is the difference between this one and the old one?
You can lay them next to each other to see the difference. With the first one, the upper frame had a padding on the bottom, whilst the lower had a padding on the top. I made it so that they both have a 2 pixel padding on the top AND on the bottom.
 
You can lay them next to each other to see the difference. With the first one, the upper frame had a padding on the bottom, whilst the lower had a padding on the top. I made it so that they both have a 2 pixel padding on the top AND on the bottom.
Ahhhh. Ok. (Didn't make the sprite, so I don't suck :p)
[DOUBLEPOST=1448685369,1448685236][/DOUBLEPOST](I looked through the ExampleMod before I asked this) how do you change the boss' healing potion drops to greater healing potions?
 
Ahhhh. Ok. (Didn't make the sprite, so I don't suck :p)
[DOUBLEPOST=1448685369,1448685236][/DOUBLEPOST](I looked through the ExampleMod before I asked this) how do you change the boss' healing potion drops to greater healing potions?
I'm not stating that the one that made the spritesheet is actually bad at it, just that he/she forgot to set the correct padding.
I've come across a LOT of artists (not specifically on this forum) that have difficulties with making animations because of this.

And uhm...:
Code:
public override void BossLoot(ref string name, ref int potionType)
{
    potionType = ItemID.SuperHealingPotion;
    base.BossLoot(ref name, ref potionType);
}
 
I have this for my boss' AI:
Code:
npc.TargetClosest(true);
// player
Vector2 enemy = Main.player[npc.target].position;
Vector2 me = npc.position;

if (enemy.X < me.X && npc.velocity.X > -6)
{
npc.velocity.X -= 0.20f;
}
if (enemy.X > me.X && npc.velocity.X < 6)
{
npc.velocity.X += 0.20f;
}

if (enemy.Y > me.Y && npc.velocity.Y < 6)
{
npc.velocity.Y += 0.20f;
}
if (enemy.Y < me.Y && npc.velocity.Y > -6)
{
npc.velocity.Y -= 0.20f;
How do I get him to hover above the player? (I'm pretty sure it would be somewhere in the if statements for the Y axis.)
 
Last edited:
My lucky guess is that that's not going to work anyways, since you're setting 'counter' in the function to 0, so if you add a value to it, the value will be 0 on the next update once again. If I were you, I'd make a plan (on how to go about what you're trying to do) on paper or something first. That'll save you a lot of brain aches.
Anyway, if you want it to wait for a set amount of time, do not use TimeSpan...
Just make a value and add to it every tick, then look if it's larger than the value you want ('6' in this case would be 0.1 second).
where do I get that exactly? I cant seem to find it :c
 
thats very vague, computers load things under a millisecond.
True, sometimes even nanoseconds, but XNA (the library used for Terraria) allows for a 'standard' framerate (a bit like vsync). This will cap your FPS at 60 and will try to make updates work towards that number (when you're experiencing frame drops). So you can safely state that there are 60 ticks every second using XNA/Terraria.
No more, no less.
 
Back
Top Bottom