private void SetFirstFrame(CCNode node, CCBSequenceProperty pSeqProp, float fTweenDuration) { List<CCBKeyframe> keyframes = pSeqProp.Keyframes; if (keyframes.Count == 0) { // Use base value (no animation) object baseValue = GetBaseValue(node, pSeqProp.Name); Debug.Assert(baseValue != null, "No baseValue found for property"); SetAnimatedProperty(pSeqProp.Name, node, baseValue, fTweenDuration); } else { // Use first keyframe CCBKeyframe keyframe = keyframes[0]; SetAnimatedProperty(pSeqProp.Name, node, keyframe.Value, fTweenDuration); } }
private CCNode ReadNodeGraph(CCNode parent) { /* Read class name. */ string className = ReadCachedString(); // Read assignment type and name var memberVarAssignmentType = (kCCBTargetType) ReadInt(false); string memberVarAssignmentName = String.Empty; if (memberVarAssignmentType != kCCBTargetType.kCCBTargetTypeNone) { memberVarAssignmentName = ReadCachedString(); } CCNodeLoader ccNodeLoader = mCCNodeLoaderLibrary.GetCCNodeLoader(className); if (ccNodeLoader == null) { CCLog.Log("no corresponding node loader for %s", className); return null; } CCNode node = ccNodeLoader.LoadCCNode(parent, this); // Set root node if (mActionManager.RootNode == null) { mActionManager.RootNode = node; } // Read animated properties var seqs = new Dictionary<int, Dictionary<string, CCBSequenceProperty>>(); mAnimatedProps.Clear(); int numSequence = ReadInt(false); for (int i = 0; i < numSequence; ++i) { int seqId = ReadInt(false); var seqNodeProps = new Dictionary<string, CCBSequenceProperty>(); int numProps = ReadInt(false); for (int j = 0; j < numProps; ++j) { var seqProp = new CCBSequenceProperty(); seqProp.Name = ReadCachedString(); seqProp.Type = (kCCBPropType) ReadInt(false); mAnimatedProps.Add(seqProp.Name); int numKeyframes = ReadInt(false); for (int k = 0; k < numKeyframes; ++k) { CCBKeyframe keyframe = ReadKeyframe(seqProp.Type); seqProp.Keyframes.Add(keyframe); } seqNodeProps.Add(seqProp.Name, seqProp); } seqs.Add(seqId, seqNodeProps); } if (seqs.Count > 0) { mActionManager.AddNode(node, seqs); } // Read properties ccNodeLoader.ParseProperties(node, parent, this); // Handle sub ccb files (remove middle node) if (node is CCBFile) { var ccbFileNode = (CCBFile) node; CCNode embeddedNode = ccbFileNode.FileNode; embeddedNode.Position = ccbFileNode.Position; embeddedNode.Rotation = ccbFileNode.Rotation; embeddedNode.Scale = ccbFileNode.Scale; embeddedNode.Tag = ccbFileNode.Tag; embeddedNode.Visible = true; embeddedNode.IgnoreAnchorPointForPosition = ccbFileNode.IgnoreAnchorPointForPosition; ccbFileNode.FileNode = null; node = embeddedNode; } #if CCB_ENABLE_JAVASCRIPT /* if (memberVarAssignmentType && memberVarAssignmentName && ![memberVarAssignmentName isEqualToString:@""]) { [[JSCocoa sharedController] setObject:node withName:memberVarAssignmentName]; }*/ #else if (memberVarAssignmentType != kCCBTargetType.kCCBTargetTypeNone) { object target = null; if (memberVarAssignmentType == kCCBTargetType.kCCBTargetTypeDocumentRoot) { target = mActionManager.RootNode; } else if (memberVarAssignmentType == kCCBTargetType.kCCBTargetTypeOwner) { target = mOwner; } if (target != null) { bool assigned = false; var targetAsCCBMemberVariableAssigner = (CCBMemberVariableAssigner) target; if (targetAsCCBMemberVariableAssigner != null) { assigned = targetAsCCBMemberVariableAssigner.OnAssignCCBMemberVariable(target, memberVarAssignmentName, node); } if (!assigned && mCCBMemberVariableAssigner != null) { mCCBMemberVariableAssigner.OnAssignCCBMemberVariable(target, memberVarAssignmentName, node); } } } #endif // CCB_ENABLE_JAVASCRIPT mAnimatedProps.Clear(); /* Read and add children. */ int numChildren = ReadInt(false); for (int i = 0; i < numChildren; i++) { CCNode child = ReadNodeGraph(node); node.AddChild(child); } // Call onNodeLoaded var nodeAsCCNodeLoaderListener = node as CCNodeLoaderListener; if (nodeAsCCNodeLoaderListener != null) { nodeAsCCNodeLoaderListener.OnNodeLoaded(node, ccNodeLoader); } else if (mCCNodeLoaderListener != null) { mCCNodeLoaderListener.OnNodeLoaded(node, ccNodeLoader); } return node; }
private void RunAction(CCNode node, CCBSequenceProperty pSeqProp, float fTweenDuration) { List<CCBKeyframe> keyframes = pSeqProp.Keyframes; int numKeyframes = keyframes.Count; if (numKeyframes > 1) { // Make an animation! var actions = new List<CCFiniteTimeAction>(); CCBKeyframe keyframeFirst = keyframes[0]; float timeFirst = keyframeFirst.Time + fTweenDuration; if (timeFirst > 0) { actions.Add(new CCDelayTime (timeFirst)); } for (int i = 0; i < numKeyframes - 1; ++i) { CCBKeyframe kf0 = keyframes[i]; CCBKeyframe kf1 = keyframes[i + 1]; CCActionInterval action = GetAction(kf0, kf1, pSeqProp.Name, node); if (action != null) { // Apply easing action = GetEaseAction(action, kf0.EasingType, kf0.EasingOpt); actions.Add(action); } } if (actions.Count > 1) { CCFiniteTimeAction seq = CCSequence.FromActions(actions.ToArray()); node.RunAction(seq); } else { node.RunAction(actions[0]); } } }