Example #1
0
        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);
            }
        }
Example #2
0
        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 = new CCSequence(actions.ToArray());
                    node.RunAction(seq);
                }
                else
                {
                    node.RunAction(actions[0]);
                }
            }
        }
Example #3
0
        public bool ReadCallbackKeyframesForSeq(CCBSequence seq)
        {
            int numKeyframes = ReadInt(false);

            if (numKeyframes == 0)
            {
                return(true);
            }

            CCBSequenceProperty channel = new CCBSequenceProperty();

            for (int i = 0; i < numKeyframes; ++i)
            {
                float  time         = ReadFloat();
                string callbackName = ReadCachedString();

                int callbackType = ReadInt(false);

                List <CCBValue> value = new List <CCBValue>();
                value.Add(new CCBValue(callbackName));
                value.Add(new CCBValue(callbackType.ToString()));

                CCBKeyframe keyframe = new CCBKeyframe();

                keyframe.Time  = time;
                keyframe.Value = value;

                if (_jsControlled)
                {
                    //string callbackIdentifier;
                    _actionManager.GetKeyframeCallbacks().Add(String.Format("{0}:{1}", callbackType, callbackName));
                }

                channel.Keyframes.Add(keyframe);
            }

            seq.CallBackChannel = channel;

            return(true);
        }
Example #4
0
        public Object ActionForSoundChannel(CCBSequenceProperty channel)
        {
            float lastKeyframeTime = 0;

            var actions      = new List <CCFiniteTimeAction>();
            var keyframes    = channel.Keyframes;
            int numKeyframes = keyframes.Count;

            for (int i = 0; i < numKeyframes; ++i)
            {
                CCBKeyframe keyframe = keyframes[i];
                float       timeSinceLastKeyframe = keyframe.Time - lastKeyframeTime;
                lastKeyframeTime = keyframe.Time;
                if (timeSinceLastKeyframe > 0)
                {
                    actions.Add(new CCDelayTime(timeSinceLastKeyframe));
                }

                var    keyVal    = (List <CCBValue>)keyframe.Value;
                string soundFile = keyVal[0].GetStringValue();

                float pitch, pan, gain;

                pitch = float.Parse(keyVal[1].GetStringValue());

                pan = float.Parse(keyVal[2].GetStringValue());

                gain = float.Parse(keyVal[3].GetStringValue());

                actions.Add(CCBSoundEffect.ActionWithSoundFile(soundFile, pitch, pan, gain));
            }

            if (actions.Count < 1)
            {
                return(null);
            }

            return(new CCSequence(actions.ToArray()));
        }
Example #5
0
        public bool ReadSoundKeyframesForSeq(CCBSequence seq)
        {
            int numKeyframes = ReadInt(false);

            if (numKeyframes == 0)
            {
                return(true);
            }

            CCBSequenceProperty channel = new CCBSequenceProperty();

            for (int i = 0; i < numKeyframes; ++i)
            {
                float  time      = ReadFloat();
                string soundFile = ReadCachedString();
                float  pitch     = ReadFloat();
                float  pan       = ReadFloat();
                float  gain      = ReadFloat();

                List <CCBValue> value = new List <CCBValue>();

                value.Add(new CCBValue(soundFile));
                value.Add(new CCBValue(pitch.ToString()));
                value.Add(new CCBValue(pan.ToString()));
                value.Add(new CCBValue(gain.ToString()));

                CCBKeyframe keyframe = new CCBKeyframe();
                keyframe.Time  = time;
                keyframe.Value = value;
                channel.Keyframes.Add(keyframe);
            }

            seq.SoundChannel = channel;

            return(true);
        }
Example #6
0
        private CCNode ReadNodeGraph(CCNode parent)
        {
            /* Read class name. */
            string className = ReadCachedString();

            string _jsControlledName = null;

            if (_jsControlled)
            {
                _jsControlledName = ReadCachedString();
            }

            // Read assignment type and name
            var memberVarAssignmentType = (CCBTargetType) ReadInt(false);

            string memberVarAssignmentName = String.Empty;
            if (memberVarAssignmentType != CCBTargetType.None)
            {
                memberVarAssignmentName = ReadCachedString();
            }

            CCNodeLoader ccNodeLoader = _nodeLoaderLibrary.GetCCNodeLoader(className);
            if (ccNodeLoader == null)
            {
                CCLog.Log("no corresponding node loader for {0}", className);
                return null;
            }

            CCNode node = ccNodeLoader.LoadCCNode(parent, this);

            // Set root node
            if (_actionManager.RootNode == null)
            {
                _actionManager.RootNode = node;
            }

            // Assign controller
            if (_jsControlled && node == _actionManager.RootNode)
            {
                _actionManager.DocumentControllerName = _jsControlledName;
            }

            // Read animated properties
            var seqs = new Dictionary<int, Dictionary<string, CCBSequenceProperty>>();
            _animatedProps.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 = (CCBPropertyType) ReadInt(false);
                    _animatedProps.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)
            {
                _actionManager.AddNode(node, seqs);
            }

            // Read properties
            ccNodeLoader.ParseProperties(node, parent, this);

            bool isCCBFileNode = node is CCBFile;

            // Handle sub ccb files (remove middle node)
            if (isCCBFileNode)
            {
                var ccbFileNode = (CCBFile) node;

                CCNode embeddedNode = ccbFileNode.FileNode;
                embeddedNode.Position = ccbFileNode.Position;
                embeddedNode.Rotation = ccbFileNode.Rotation;
                embeddedNode.ScaleX = ccbFileNode.ScaleX;
                embeddedNode.ScaleY = ccbFileNode.ScaleY;
                embeddedNode.Tag = ccbFileNode.Tag;
                embeddedNode.Visible = true;
                //embeddedNode.IgnoreAnchorPointForPosition = ccbFileNode.IgnoreAnchorPointForPosition;

                _actionManager.MoveAnimationsFromNode(ccbFileNode, embeddedNode);

                ccbFileNode.FileNode = null;

                node = embeddedNode;
            }

#if CCB_ENABLE_JAVASCRIPT
    /*
     if (memberVarAssignmentType && memberVarAssignmentName && ![memberVarAssignmentName isEqualToString:@""])
     {
     [[JSCocoa sharedController] setObject:node withName:memberVarAssignmentName];
     }*/
#else
            if (memberVarAssignmentType != CCBTargetType.None)
            {
                if (!_jsControlled)
                {
                    object target = null;
                    if (memberVarAssignmentType == CCBTargetType.DocumentRoot)
                    {
                        target = _actionManager.RootNode;
                    }
                    else if (memberVarAssignmentType == CCBTargetType.Owner)
                    {
                        target = _owner;
                    }

                    if (target != null)
                    {
                        var targetAsCCBMemberVariableAssigner = target as ICCBMemberVariableAssigner;

                        bool assigned = false;
                        if (memberVarAssignmentType != CCBTargetType.None)
                        {
                            if (targetAsCCBMemberVariableAssigner != null)
                            {
                                assigned = targetAsCCBMemberVariableAssigner.OnAssignCCBMemberVariable(target,
                                                                                                       memberVarAssignmentName,
                                                                                                       node);
                            }

                            if (!assigned && _CCBMemberVariableAssigner != null)
                            {
                                _CCBMemberVariableAssigner.OnAssignCCBMemberVariable(target, memberVarAssignmentName,
                                                                                     node);
                            }
                        }
                    }
                }
                else
                {
                    if (memberVarAssignmentType == CCBTargetType.DocumentRoot)
                    {
                        _actionManager.AddDocumentOutletName(memberVarAssignmentName);
                        _actionManager.AddDocumentOutletNode(node);
                    }
                    else
                    {
                        _ownerOutletNames.Add(memberVarAssignmentName);
                        _ownerOutletNodes.Add(node);
                    }
                }
            }

            // Assign custom properties.
    if (ccNodeLoader.CustomProperties.Count > 0)
    {
        bool customAssigned = false;
        
        if(!_jsControlled)
        {
            Object target = node;
            if(target != null)
            {
                ICCBMemberVariableAssigner targetAsCCBMemberVariableAssigner = target as ICCBMemberVariableAssigner;
                if(targetAsCCBMemberVariableAssigner != null) {
                    
                    var pCustomPropeties = ccNodeLoader.CustomProperties;
                    foreach (var pElement in pCustomPropeties)
                    {
                        customAssigned = targetAsCCBMemberVariableAssigner.OnAssignCCBCustomProperty(target, pElement.Key, pElement.Value);

                        if(!customAssigned && _CCBMemberVariableAssigner != null)
                        {
                            customAssigned = _CCBMemberVariableAssigner.OnAssignCCBCustomProperty(target, pElement.Key, pElement.Value);
                        }
                    }
                }
            }
        }
    }
#endif
            // CCB_ENABLE_JAVASCRIPT

            _animatedProps.Clear();

            /* Read and add children. */
            int numChildren = ReadInt(false);
            for (int i = 0; i < numChildren; i++)
            {
                CCNode child = ReadNodeGraph(node);
                node.AddChild(child);
            }

            if (!isCCBFileNode)
            {
                // Call onNodeLoaded
                var nodeAsCCNodeLoaderListener = node as ICCNodeLoaderListener;
                if (nodeAsCCNodeLoaderListener != null)
                {
                    nodeAsCCNodeLoaderListener.OnNodeLoaded(node, ccNodeLoader);
                }
                else if (_nodeLoaderListener != null)
                {
                    _nodeLoaderListener.OnNodeLoaded(node, ccNodeLoader);
                }
            }

            return node;
        }
Example #7
0
        public bool ReadSoundKeyframesForSeq(CCBSequence seq)
        {
            int numKeyframes = ReadInt(false);
            if (numKeyframes == 0) return true;

            CCBSequenceProperty channel = new CCBSequenceProperty();

            for (int i = 0; i < numKeyframes; ++i)
            {

                float time = ReadFloat();
                string soundFile = ReadCachedString();
                float pitch = ReadFloat();
                float pan = ReadFloat();
                float gain = ReadFloat();

                List<CCBValue> value = new List<CCBValue>();

                value.Add(new CCBValue(soundFile));
                value.Add(new CCBValue(pitch.ToString()));
                value.Add(new CCBValue(pan.ToString()));
                value.Add(new CCBValue(gain.ToString()));

                CCBKeyframe keyframe = new CCBKeyframe();
                keyframe.Time = time;
                keyframe.Value = value;
                channel.Keyframes.Add(keyframe);
            }

            seq.SoundChannel = channel;

            return true;
        }
Example #8
0
        public bool ReadCallbackKeyframesForSeq(CCBSequence seq)
        {
            int numKeyframes = ReadInt(false);
            if (numKeyframes == 0) return true;

            CCBSequenceProperty channel = new CCBSequenceProperty();
            
            for (int i = 0; i < numKeyframes; ++i)
            {

                float time = ReadFloat();
                string callbackName = ReadCachedString();

                int callbackType = ReadInt(false);

                List<CCBValue> value = new List<CCBValue>();
                value.Add(new CCBValue(callbackName));
                value.Add(new CCBValue(callbackType.ToString()));

                CCBKeyframe keyframe = new CCBKeyframe();

                keyframe.Time = time;
                keyframe.Value = value;

                if (_jsControlled)
                {
                    //string callbackIdentifier;
                    _actionManager.GetKeyframeCallbacks().Add(String.Format("{0}:{1}", callbackType, callbackName));
                }

                channel.Keyframes.Add(keyframe);
            }

            seq.CallBackChannel = channel;

            return true;
        }
Example #9
0
        public void RunAnimations(int nSeqId, float fTweenDuration)
        {
            Debug.Assert(nSeqId != -1, "Sequence id couldn't be found");

            mRootNode.StopAllActions();

            foreach (var pElement in mNodeSequences)
            {
                CCNode node = pElement.Key;
                node.StopAllActions();

                // Refer to CCBReader::readKeyframe() for the real type of value
                Dictionary <int, Dictionary <string, CCBSequenceProperty> > seqs = pElement.Value;

                var seqNodePropNames = new List <string>();

                Dictionary <string, CCBSequenceProperty> seqNodeProps;
                if (seqs.TryGetValue(nSeqId, out seqNodeProps))
                {
                    // Reset nodes that have sequence node properties, and run actions on them
                    foreach (var pElement1 in seqNodeProps)
                    {
                        string propName             = pElement1.Key;
                        CCBSequenceProperty seqProp = pElement1.Value;
                        seqNodePropNames.Add(propName);

                        SetFirstFrame(node, seqProp, fTweenDuration);
                        RunAction(node, seqProp, fTweenDuration);
                    }
                }

                // Reset the nodes that may have been changed by other timelines
                Dictionary <string, object> nodeBaseValues;
                if (mBaseValues.TryGetValue(node, out nodeBaseValues))
                {
                    foreach (var pElement2 in nodeBaseValues)
                    {
                        if (!seqNodePropNames.Contains(pElement2.Key))
                        {
                            object value = pElement2.Value;

                            if (value != null)
                            {
                                SetAnimatedProperty(pElement2.Key, node, value, fTweenDuration);
                            }
                        }
                    }
                }
            }

            // Make callback at end of sequence
            CCBSequence seq            = GetSequence(nSeqId);
            CCAction    completeAction = new CCSequence(
                new CCDelayTime(seq.Duration + fTweenDuration),
                new CCCallFunc(SequenceCompleted)
                );

            mRootNode.RunAction(completeAction);

            // Set the running scene
            mRunningSequence = GetSequence(nSeqId);
        }
Example #10
0
        private CCNode ReadNodeGraph(CCNode parent)
        {
            /* Read class name. */
            string className = ReadCachedString();

            // Read assignment type and name
            var memberVarAssignmentType = (CCBTargetType)ReadInt(false);

            string memberVarAssignmentName = String.Empty;

            if (memberVarAssignmentType != CCBTargetType.None)
            {
                memberVarAssignmentName = ReadCachedString();
            }

            CCNodeLoader ccNodeLoader = mCCNodeLoaderLibrary.GetCCNodeLoader(className);

            if (ccNodeLoader == null)
            {
                CCLog.Log("no corresponding node loader for {0}", 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 = (CCBPropType)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 != CCBTargetType.None)
            {
                object target = null;
                if (memberVarAssignmentType == CCBTargetType.DocumentRoot)
                {
                    target = mActionManager.RootNode;
                }
                else if (memberVarAssignmentType == CCBTargetType.Owner)
                {
                    target = mOwner;
                }

                if (target != null)
                {
                    bool assigned = false;

                    var targetAsCCBMemberVariableAssigner = (ICCBMemberVariableAssigner)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 ICCNodeLoaderListener;
            if (nodeAsCCNodeLoaderListener != null)
            {
                nodeAsCCNodeLoaderListener.OnNodeLoaded(node, ccNodeLoader);
            }
            else if (mCCNodeLoaderListener != null)
            {
                mCCNodeLoaderListener.OnNodeLoaded(node, ccNodeLoader);
            }

            return(node);
        }
Example #11
0
        public Object ActionForCallbackChannel(CCBSequenceProperty channel)
        {
            float lastKeyframeTime = 0;

            var actions      = new List <CCFiniteTimeAction>();
            var keyframes    = channel.Keyframes;
            int numKeyframes = keyframes.Count;

            for (int i = 0; i < numKeyframes; ++i)
            {
                CCBKeyframe keyframe = keyframes[i];
                float       timeSinceLastKeyframe = keyframe.Time - lastKeyframeTime;
                lastKeyframeTime = keyframe.Time;
                if (timeSinceLastKeyframe > 0)
                {
                    actions.Add(new CCDelayTime(timeSinceLastKeyframe));
                }

                var           keyVal         = (List <CCBValue>)keyframe.Value;
                string        selectorName   = keyVal[0].GetStringValue();
                CCBTargetType selectorTarget =
                    (CCBTargetType)int.Parse(keyVal[1].GetStringValue());

                if (_jsControlled)
                {
                    string     callbackName = string.Format("{0}:{1}", selectorTarget, selectorName);
                    CCCallFunc callback     = (CCCallFunc)_keyframeCallFuncs[callbackName].Copy();

                    if (callback != null)
                    {
                        actions.Add(callback);
                    }
                }
                else
                {
                    Object target = null;

                    if (selectorTarget == CCBTargetType.DocumentRoot)
                    {
                        target = _rootNode;
                    }
                    else if (selectorTarget == CCBTargetType.Owner)
                    {
                        target = _owner;
                    }

                    if (target != null)
                    {
                        if (selectorName.Length > 0)
                        {
                            Action <CCNode> selCallFunc = null;

                            ICCBSelectorResolver targetAsCCBSelectorResolver = target as ICCBSelectorResolver;

                            if (targetAsCCBSelectorResolver != null)
                            {
                                selCallFunc = targetAsCCBSelectorResolver.OnResolveCCBCCCallFuncSelector(target,
                                                                                                         selectorName);
                            }

                            if (selCallFunc == null)
                            {
                                CCLog.Log("Skipping selector {0} since no CCBSelectorResolver is present.",
                                          selectorName);
                            }
                            else
                            {
                                CCCallFuncN callback = new CCCallFuncN(selCallFunc);
                                actions.Add(callback);
                            }
                        }
                        else
                        {
                            CCLog.Log("Unexpected empty selector.");
                        }
                    }
                }
            }
            if (actions.Capacity < 1)
            {
                return(null);
            }

            return(new CCSequence(actions.ToArray()));
        }
        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]);
                }
            }
        }
        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);
            }
        }
Example #14
0
        public Object ActionForSoundChannel(CCBSequenceProperty channel)
        {
            float lastKeyframeTime = 0;

            var actions = new List<CCFiniteTimeAction>();
            var keyframes = channel.Keyframes;
            int numKeyframes = keyframes.Count;

            for (int i = 0; i < numKeyframes; ++i)
            {

                CCBKeyframe keyframe = keyframes[i];
                float timeSinceLastKeyframe = keyframe.Time - lastKeyframeTime;
                lastKeyframeTime = keyframe.Time;
                if (timeSinceLastKeyframe > 0)
                {
                    actions.Add(new CCDelayTime(timeSinceLastKeyframe));
                }

                var keyVal =  (List<CCBValue>)keyframe.Value;
                string soundFile = keyVal[0].GetStringValue();

                float pitch, pan, gain;

                pitch = float.Parse(keyVal[1].GetStringValue());

                pan = float.Parse(keyVal[2].GetStringValue());

                gain = float.Parse(keyVal[3].GetStringValue());

                actions.Add(CCBSoundEffect.ActionWithSoundFile(soundFile, pitch, pan, gain));
            }

            if (actions.Count < 1) return null;

            return new CCSequence(actions.ToArray());
        }
Example #15
0
        public Object ActionForCallbackChannel(CCBSequenceProperty channel)
        {
            float lastKeyframeTime = 0;

            var actions = new List<CCFiniteTimeAction>();
            var keyframes = channel.Keyframes;
            int numKeyframes = keyframes.Count;

            for (int i = 0; i < numKeyframes; ++i)
            {

                CCBKeyframe keyframe = keyframes[i];
                float timeSinceLastKeyframe = keyframe.Time - lastKeyframeTime;
                lastKeyframeTime = keyframe.Time;
                if (timeSinceLastKeyframe > 0)
                {
                    actions.Add(new CCDelayTime(timeSinceLastKeyframe));
                }

                var keyVal = (List<CCBValue>)keyframe.Value;
                string selectorName = keyVal[0].GetStringValue();
                CCBTargetType selectorTarget =
                    (CCBTargetType) int.Parse(keyVal[1].GetStringValue());

                if (_jsControlled)
                {
                    string callbackName = string.Format("{0}:{1}", selectorTarget, selectorName);
                    CCCallFunc callback = (CCCallFunc) _keyframeCallFuncs[callbackName].Copy();

                    if (callback != null)
                    {
                        actions.Add(callback);
                    }
                }
                else
                {
                    Object target = null;

                    if (selectorTarget == CCBTargetType.DocumentRoot)
                        target = _rootNode;
                    else if (selectorTarget == CCBTargetType.Owner)
                        target = _owner;

                    if (target != null)
                    {
                        if (selectorName.Length > 0)
                        {
                            Action<CCNode> selCallFunc = null;

                            ICCBSelectorResolver targetAsCCBSelectorResolver = target as ICCBSelectorResolver;

                            if (targetAsCCBSelectorResolver != null)
                            {
                                selCallFunc = targetAsCCBSelectorResolver.OnResolveCCBCCCallFuncSelector(target,
                                                                                                          selectorName);
                            }

                            if (selCallFunc == null)
                            {
                                CCLog.Log("Skipping selector {0} since no CCBSelectorResolver is present.",
                                      selectorName);
                            }
                            else
                            {
                                CCCallFuncN callback = new CCCallFuncN(selCallFunc);
                                actions.Add(callback);
                            }
                        }
                        else
                        {
                            CCLog.Log("Unexpected empty selector.");
                        }
                    }
                }
            }
            if (actions.Capacity < 1) return null;

            return new CCSequence(actions.ToArray());
        }