Is there a way to get what frame the animation is on?
I can get displayFrame which returns the rect but I want the index.
Am I missing something?
A fast, easy to use, free, and community supported 2D game engine
Is there a way to get what frame the animation is on?
I can get displayFrame which returns the rect but I want the index.
Am I missing something?
I don't think so, although I may be wrong.
If your sprite is subclassed and you are controlling your animation through updating setFrame with a timer and incrementing integer property frame, then just query the frame property. I did this and it works nicely. Let me know if you'd like more info.
hth Jonathan
-shape reactor-
Bumping the original question.
I am using the Animate action and I am looking for a way to keep track of the current frame number. I tried running a scheduler with the same rate as my animation but it does not seem to sync with the same rate as the animation.
I'm a complete Cocos2D newbie so I may be doing this completely wrong but if anyone can tell if I'm on the good path with this it would be nice:
// (Not the exact code, simplified version for explanation purposes)
animation = [[AtlasAnimation animationWithName:animTag delay:1.0/30.0] retain];
action = [[RepeatForever actionWithAction:animation] retain];
[self runAction:action];
frameCount = 0;
[self schedule:@selector(onUpdate:) interval:1.0/30.0];
// ...
- (void) onUpdate:(ccTime) delta {
frameCount++;
if (frameCount == 10) {
[self stopAction:action];
// The animation stops on frame 3 after playing
// the 10 frames for a first time
}
}You must log in to post.