views:

45

answers:

2

so I have this spritesheet (4 sprites in a row and 3 in a coloumn) which I use to animate a character in a game I make. It animates just fine without a problem, like I want it to

the problem start to arise when I want to change the state from "dash" (running to the enemy) to "attack" (well, attack the enemy) it doesn't seem to play the attack sprite from the start (index 0)

I've used self._currentFrame = 3 on the set_state(self) function so that when the function changes it resets the frame to the third frame, which makes (self.currentFrame + 1) % 4 returns 0

but still, sometimes it doesn't do what I want, and start the animation at about index 2 or 3 (the end of animation). How do I make sure that my animation starts at index 0?

my updating code is as follows, if it helps

    self.frameTime += dt

    if self.fps is not -1:
        while self.frameTime > 1.0 / self.fps:
            self.frameTime -= 1.0 / self.fps
            self.currentFrame = (self.currentFrame + 1) % 4
            self.currentVFrame = (self.currentVFrame + 1) % 3
A: 

Have you tested to ensure the starting value actually is 3, before that logic is executed? I ask because your summary includes reference to self._currentFrame, when your code refers to self.currentFrame -- are you assigning to one variable and checking another?

Edit regarding the additional 'answer' posted by the question starter:
Please see http://meta.stackoverflow.com/questions/5234/how-does-accepting-an-answer-work for instructions on how (and when) to accept an answer, as well as why it's advantageous for you to do so with each question you ask.

Andrew
ah that was my mistake, I code the child class first before take that currentFrame to the parent. But I've corrected the code now, and I've printed the value before the logic executedyes the value is 3 before the logic runs, but it only works like I want it to when the value is printed once. Oftenly the value 3 printed 3 times before it becomes 0 (which means index 3 was rendered first)I don't know how to control the value so it printed as 3 once everytime it attacks, any ideas?
Daggio
You'll need to update your question with additional code if you'd like anyone to be able to help you further (e.g., the code involved that assigns 3 to `self.currentFrame`).
Andrew
A: 

Thanks Andrew, but I've solved it. It turned out I just need to adjust the self.fps(the animation fps, not the screen) so that 1.0 / self.fps is smaller than self.frameTime

Thanks Andrew, is there any way I can give you reputation? or end this question?

edit: why the currentFrame printed as 3? The Actor class (the class that inherited from AnimatedGameObject) has a set_state(self, newState) function (which changes the self.currentFrame to 3) that changes the state, so that the update code above (as I've explained) returns 0 and the animation starts at the beginning of the frame

The problem is when the self.fps in the update(self, dt) function has a value of 4, the 1.0 / self.fps has a lesser value than the self.frameTime and as the effect, the self.currentFrame is not set to 0 at the beginning of the animation So I actually just need to double the self.fps to 8 and the code works just like I want it to

Daggio