Good Evening,
i seem to be having an issue with my animations using SDL. the animations work, its basically just a static sprite swap, "Witch" for instance is just a lady stiring a big cauldron... anyways, whats hapening is the speeds for the sprites are different, but whichever speed was last set in the second set of code, is the speed that sets for every other animation... any ideas how to fix this?
yes the gDeltaTime is used as a multiplier with the speed variable. im still new to c++ so if i understand correctly what a member variable is, i could, would that make a difference? essentially all the animations are being run at the one speed vs the different ones.. also static was just a naming convention. the function just iterates through the sprite indices on a timer, i meant static as these animations arent moving around the map.
it looks like it is supposed to swap current with itself repeatedly until the time for the next image comes around, which looks like a fair bit of work to do nothing. It seems like it should short circuit when there is no work to do.
swapTimer += animSwapSpeed * gDeltaTime;
this just does not look correct. I am trying to see what it should be, but what i advise you to do is to do this yourself:
get rid of all the animations except 1.
print swaptimer every iteration for a while, 30 seconds or whatever. Also print the index computed from it and the current time stamp. This should tell you whether this logic is correct or not.
i will try this, however i would like to add, individually they all work. but once they're all running together is when the speed is being overwritten.
EDIT: i agree, the way that is working... i dunno my teacher helped me put that in, im not sure how it even works right at all...
ill try to stream line this, again im like 4 weeks into learning c++ so im still a noob. ill add the swaptimer to the class, and see if this works out better for me.
EDIT:: everything you see up above is in a class, this is my AISprite class... the gameloop is my GameManager.cpp.. the second set of code in OP is the function thats being called in update in the gamemanager
curious, how would you recommend putting in the timer for each individual animation? i put in the swap timer and passed it through as an argument, but the timer stays at zero now.
put those variables inside the actual class like this:
class AISprite
{
public:
float swapTimer;
... etc
}
if you pass it as a parameter, you need to put & in front of it if you want to retain the value:
void modifyx(int &x)
{
x = rand();
}
int z = 0;
modifyx(z); //z will change. without the &, it will not.
but that won't solve your problem because you still only have ONE copy of the variable for all the animations, which is not logically correct for this job.
Glad it worked.
It takes a while to get past hackery. Hackery isn't all bad, it means you have learned some piece of the language and made it work, even if its not the best way. That stirs the problem solving brain cells around in good ways.
I am guessing, but I think you misunderstood the idea of putting a class in its own cpp/.h files and took that to mean the things in those files belong to the class. Organizing the code into files is for the humans, the compiler really does not care what you put where if its legal, and its ok (to the compiler) to have many classes in 1 set of files or even one huge monolithic main or stuff that isn't part of the class buried in the class cpp file (that is what you had here).