Here are my tools: CocosBuilder-2.1/CCBReader-2.1/cocos2d-iphone-2.0
I created TestNode.ccb
(root object is CCNode), in it I create 2 timeline,@"t0name"
(2s long) and @"t1name"
(2s long),
root node is set to custom class TestNode
I created TestNode.h
:
#import "CCBAnimationManager.h"
@interface TestNode : CCNode <CCBAnimationManagerDelegate>{
}
@property (nonatomic, assign) BOOL condition;
@property (nonatomic, assign) BOOL t1Played;
-(void)playAnimation:(NSString *)name;
-(void)playAnimation;
@end
and here is the TestNode.m
:
#import "TestNode.h"
#import "CCBReader.h"
@implementation TestNode
@synthesize condition;
@synthesize t1Played;
-(void)playAnimation:(NSString *)name{
CCBAnimationManager* animationManager = self.userObject;
[animationManager runAnimationsForSequenceNamed:name];
}
-(void)playAnimation{
if(self.condition==YES) {
[self playAnimation:@"t1name"];
self.t1played=YES;
}else{
[self playAnimation:@"t0name"];
}
}
-(void)didLoadFromCCB{
CCBAnimationManager* animationManager = self.userObject;
animationManager.delegate = self;
}
-(void)completedAnimationSequenceNamed:(NSString *)pName{
if (self.t1played==YES) {
NSLog(@"t1played");
}else{
[self playAnimation];
}
}
@end
There is also a main layer (TestScene.h/.m
), in this scene i will add CCNode
and some thing else...
Normal case:
In the main layer's onEnter(
), I add an instance of TestNode
and call it's playAnimation, according to the code above, the timeline named @"t0name"
will be played forever, and what really happened is the same to my assumption.
Strange case:
In the main layer's onEnter()
, I add an instance of TestNode
and call it's playAnimation
, AND schedule a function [self schedule:@selector(changeTestNodeCondition) interval:1.0];
this function(changeTestNodeCondition
) just set TestNode
's condition to YES, according to the code above, the timeline named @"t0name"
wil be played once(t0'
length is 2s), then timeline named @"t1name"
will be played once, then console will print "t1played" and everything stop, but what happened is:
- timeline named
@"t0name"
played once - timeline named
@"t1name"
played once - console print "t1played"
- timeline named
@"t0name"
played again - console print "t1played" again
Why step4 happened? it cause completedAnimationSequenceNamed:(NSString *) name
is called again and console print "t1played" again(step 5)
I checkd the TestNode.ccb
, both timeline has no chained timeline, both timeline unchecked auto play, @"t0name"
has sequenceId 0
, @"t0name"
has sequenceId 1
, is timeline 0
autoplayed ??? Why???
I did another interesting experiment: I change timeline @"t0name"
sequence id to 1, change timeline @"t1name
" sequence id to 2 (edit the ccb file directly using any text editor), following thing happen:
- timeline named @"t0name" played once
- timeline named @"t1name" played once
- console print "t1played"
- console print "t1played" again and again and again... dead loop
I guess in this case CCAnimationManager
try to play timeline 0
, but timeline 0
is not there so there is no animation can be seen but the "play" operation is called and then completedAnimationSequenceNamed:(NSString *) name
is called!