這是一個與CocosBuilder 2.1兼容的解決方案。 以下功能添加到CCBAnimationManager類:
- (void)enumeratePropertiesForSequence:(NSString*)name Block:(BOOL(^)(CCNode *node, CCBSequenceProperty *seqProp))block
{
int seqId = [self sequenceIdForSequenceNamed:name];
if (seqId == -1)
{
NSLog(@"Sequence %@ couldn't be found",name);
return;
}
for (NSValue* nodePtr in nodeSequences)
{
CCNode* node = [nodePtr pointerValue];
NSDictionary* seqs = [nodeSequences objectForKey:nodePtr];
NSDictionary* seqNodeProps = [seqs objectForKey:[NSNumber numberWithInt:seqId]];
// Nodes that have sequence node properties
for (NSString* propName in seqNodeProps)
{
CCBSequenceProperty* seqProp = [seqNodeProps objectForKey:propName];
if (!block(node, seqProp))
return;
}
}
}
使用此枚舉您可以訪問所有可用的屬性,例如如果你有興趣只是位置則:
#import "MyClass.h"
#import "CCBAnimationManager.h"
#import "CCBSequenceProperty.h"
#import "CCBKeyframe.h"
#import "CCNode+CCBRelativePositioning.h"
@implementation MyClass
-(void)fn
{
CCBAnimationManager* animationManager = self.userObject;
BOOL(^block)(CCNode *node, CCBSequenceProperty *seqProp) =
^BOOL(CCNode *node, CCBSequenceProperty *seqProp)
{
NSLog(@"Node tag %d, Prop name [%@], type %d", node.tag, seqProp.name, seqProp.type);
for (CCBKeyframe *kf in seqProp.keyframes)
{
if ([seqProp.name isEqualToString:@"position"])
{
id value = kf.value;
// Get relative position
float x = [[value objectAtIndex:0] floatValue];
float y = [[value objectAtIndex:1] floatValue];
// Get position type
int type = [[[self.userObject baseValueForNode:node propertyName:seqProp.name] objectAtIndex:2] intValue];
CGSize containerSize = [self.userObject containerSize:node.parent];
CGPoint absPos = [node absolutePositionFromRelative:ccp(x,y) type:type parentSize:containerSize propertyName:seqProp.name];
NSLog(@"--- relative position (%f, %f), type %d, abs position (%f, %f)", x, y, type, absPos.x, absPos.y);
}
}
return YES; // YES to continue, NO to stop enumeration
};
[animationManager enumeratePropertiesForSequence:@"MySequence" Block:block];
}
@end
這裏是如何實例MyClass的,並呼籲枚舉:
CCNode *myclass = [CCBReader nodeGraphFromFile:@"MyClass.ccbi"];
[myclass fn];
這是更好地使用CocosBuilder效果進行一個簡單的開機動畫。即使有可能,最好綁定你的spr1,...並更改代碼中的位置。 –