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 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];

                    CCFiniteTimeAction 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]);
                }
            }
        }
Exemplo n.º 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);
        }
        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(new CCBSoundEffect(soundFile, pitch, pan, gain));
            }

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

            return(new CCSequence(actions.ToArray()));
        }
Exemplo n.º 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);
        }
Exemplo n.º 6
0
        private CCBKeyframe ReadKeyframe(CCBPropertyType type)
        {
            var keyframe = new CCBKeyframe();

            keyframe.Time = ReadFloat();

            var easingType = (CCBEasingType) ReadInt(false);
            float easingOpt = 0;
            object value = null;

            if (easingType == CCBEasingType.CubicIn
                || easingType == CCBEasingType.CubicOut
                || easingType == CCBEasingType.CubicInOut
                || easingType == CCBEasingType.ElasticIn
                || easingType == CCBEasingType.ElasticOut
                || easingType == CCBEasingType.ElasticInOut)
            {
                easingOpt = ReadFloat();
            }
            keyframe.EasingType = easingType;
            keyframe.EasingOpt = easingOpt;

            if (type == CCBPropertyType.Check)
            {
                value = new CCBValue(ReadBool());
            }
            else if (type == CCBPropertyType.Byte)
            {
                value = new CCBValue(ReadByte());
            }
            else if (type == CCBPropertyType.Color3)
            {
                byte r = ReadByte();
                byte g = ReadByte();
                byte b = ReadByte();

                var c = new CCColor3B(r, g, b);
                value = new CCColor3BWapper(c);
            }
            else if (type == CCBPropertyType.Degrees)
            {
                value = new CCBValue(ReadFloat());
            }
            else if (type == CCBPropertyType.ScaleLock || type == CCBPropertyType.Position || type == CCBPropertyType.FloatXY)
            {
                float a = ReadFloat();
                float b = ReadFloat();

                value = new List<CCBValue>
                    {
                        new CCBValue(a),
                        new CCBValue(b)
                    };
            }
            else if (type == CCBPropertyType.SpriteFrame)
            {
                string spriteSheet = ReadCachedString();
                string spriteFile = ReadCachedString();

                CCSpriteFrame spriteFrame;

                if (String.IsNullOrEmpty(spriteSheet))
                {
                    spriteFile = _CCBRootPath + spriteFile;

                    CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage(CCFileUtils.RemoveExtension(spriteFile));
                    var bounds = new CCRect(0, 0, texture.ContentSizeInPixels.Width, texture.ContentSizeInPixels.Height);
                    spriteFrame = new CCSpriteFrame(texture, bounds);
                }
                else
                {
                    spriteSheet = _CCBRootPath + spriteSheet;
                    CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache;

                    // Load the sprite sheet only if it is not loaded            
                    if (!_loadedSpriteSheets.Contains(spriteSheet))
                    {
                        frameCache.AddSpriteFrames(spriteSheet);
                        _loadedSpriteSheets.Add(spriteSheet);
                    }

                    spriteFrame = frameCache[spriteFile];
                }
                value = spriteFrame;
            }

            keyframe.Value = value;

            return keyframe;
        }
Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 9
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.RotationX = ccbFileNode.RotationX;
                embeddedNode.RotationY = ccbFileNode.RotationY;
                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);
        }
Exemplo n.º 10
0
        private CCBKeyframe ReadKeyframe(CCBPropertyType type)
        {
            var keyframe = new CCBKeyframe();

            keyframe.Time = ReadFloat();

            var    easingType = (CCBEasingType)ReadInt(false);
            float  easingOpt  = 0;
            object value      = null;

            if (easingType == CCBEasingType.CubicIn ||
                easingType == CCBEasingType.CubicOut ||
                easingType == CCBEasingType.CubicInOut ||
                easingType == CCBEasingType.ElasticIn ||
                easingType == CCBEasingType.ElasticOut ||
                easingType == CCBEasingType.ElasticInOut)
            {
                easingOpt = ReadFloat();
            }
            keyframe.EasingType = easingType;
            keyframe.EasingOpt  = easingOpt;

            if (type == CCBPropertyType.Check)
            {
                value = new CCBValue(ReadBool());
            }
            else if (type == CCBPropertyType.Byte)
            {
                value = new CCBValue(ReadByte());
            }
            else if (type == CCBPropertyType.Color3)
            {
                byte r = ReadByte();
                byte g = ReadByte();
                byte b = ReadByte();

                var c = new CCColor3B(r, g, b);
                value = new CCColor3BWapper(c);
            }
            else if (type == CCBPropertyType.Degrees)
            {
                value = new CCBValue(ReadFloat());
            }
            else if (type == CCBPropertyType.ScaleLock || type == CCBPropertyType.Position || type == CCBPropertyType.FloatXY)
            {
                float a = ReadFloat();
                float b = ReadFloat();

                value = new List <CCBValue>
                {
                    new CCBValue(a),
                    new CCBValue(b)
                };
            }
            else if (type == CCBPropertyType.SpriteFrame)
            {
                string spriteSheet = ReadCachedString();
                string spriteFile  = ReadCachedString();

                CCSpriteFrame spriteFrame;

                if (String.IsNullOrEmpty(spriteSheet))
                {
                    spriteFile = _CCBRootPath + spriteFile;

                    CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage(CCFileUtils.RemoveExtension(spriteFile));
                    var         bounds  = new CCRect(0, 0, texture.ContentSizeInPixels.Width, texture.ContentSizeInPixels.Height);
                    spriteFrame = new CCSpriteFrame(texture, bounds);
                }
                else
                {
                    spriteSheet = _CCBRootPath + spriteSheet;
                    CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache;

                    // Load the sprite sheet only if it is not loaded
                    if (!_loadedSpriteSheets.Contains(spriteSheet))
                    {
                        frameCache.AddSpriteFrames(spriteSheet);
                        _loadedSpriteSheets.Add(spriteSheet);
                    }

                    spriteFrame = frameCache[spriteFile];
                }
                value = spriteFrame;
            }

            keyframe.Value = value;

            return(keyframe);
        }
Exemplo n.º 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];

                    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()));
        }
Exemplo n.º 12
0
        private void SetAnimatedProperty(string pPropName, CCNode node, object pValue, float fTweenDuraion)
        {
            if (fTweenDuraion > 0)
            {
                // Create a fake keyframe to generate the action from
                var kf1 = new CCBKeyframe();
                kf1.Value      = pValue;
                kf1.Time       = fTweenDuraion;
                kf1.EasingType = CCBEasingType.Linear;

                // Animate
                CCFiniteTimeAction tweenAction = GetAction(null, kf1, pPropName, node);
                node.RunAction(tweenAction);
            }
            else
            {
                // Just set the value

                if (pPropName == "position")
                {
                    // Get position type
                    var array = (List <CCBValue>)GetBaseValue(node, pPropName);
                    var type  = (CCBPositionType)array[2].GetIntValue();

                    // Get relative position
                    var   value = (List <CCBValue>)pValue;
                    float x     = value[0].GetFloatValue();
                    float y     = value[1].GetFloatValue();

                    node.Position = CCBHelper.GetAbsolutePosition(new CCPoint(x, y), type, GetContainerSize(node.Parent), pPropName);
                }
                else if (pPropName == "scale")
                {
                    // Get scale type
                    var array = (List <CCBValue>)GetBaseValue(node, pPropName);
                    var type  = (CCBScaleType)array[2].GetIntValue();

                    // Get relative scale
                    var   value = (List <CCBValue>)pValue;
                    float x     = value[0].GetFloatValue();
                    float y     = value[1].GetFloatValue();

                    CCBHelper.SetRelativeScale(node, x, y, type, pPropName);
                }
                else if (pPropName == "skew")
                {
                    // Get relative scale
                    var   value = (List <CCBValue>)pValue;
                    float x     = value[0].GetFloatValue();
                    float y     = value[1].GetFloatValue();

                    node.SkewX = x;
                    node.SkewY = y;
                }
                else
                {
                    // [node setValue:value forKey:name];

                    // TODO only handle rotation, opacity, displayFrame, color
                    if (pPropName == "rotation")
                    {
                        float rotate = ((CCBValue)pValue).GetFloatValue();
                        node.Rotation = rotate;
                    }
                    else if (pPropName == "rotationX")
                    {
                        float rotate = ((CCBValue)pValue).GetFloatValue();
                        node.RotationX = rotate;
                    }
                    else if (pPropName == "rotationY")
                    {
                        float rotate = ((CCBValue)pValue).GetFloatValue();
                        node.RotationY = rotate;
                    }
                    else if (pPropName == "opacity")
                    {
                        byte opacity = ((CCBValue)pValue).GetByteValue();
                        node.Opacity = opacity;
                    }
                    else if (pPropName == "displayFrame")
                    {
                        ((CCSprite)node).SpriteFrame = (CCSpriteFrame)pValue;
                    }
                    else if (pPropName == "color")
                    {
                        var color = (CCColor3BWapper)pValue;
                        node.Color = color.Color;
                    }
                    else if (pPropName == "visible")
                    {
                        bool visible = ((CCBValue)pValue).GetBoolValue();
                        node.Visible = visible;
                    }
                    else
                    {
                        CCLog.Log("unsupported property name is {0}", pPropName);
                        Debug.Assert(false, "unsupported property now");
                    }
                }
            }
        }
Exemplo n.º 13
0
        private CCFiniteTimeAction GetAction(CCBKeyframe pKeyframe0, CCBKeyframe pKeyframe1, string pPropName, CCNode node)
        {
            float duration = pKeyframe1.Time - (pKeyframe0 != null ? pKeyframe0.Time : 0);

            switch (pPropName)
            {
            case "rotationX":
            {
                CCBValue value = (CCBValue)pKeyframe1.Value;
                return(new CCBRotateXTo(duration, value.GetFloatValue()));
            }

            case "rotationY":
            {
                CCBValue value = (CCBValue)pKeyframe1.Value;
                return(new CCBRotateYTo(duration, value.GetFloatValue()));
            }

            case "rotation":
            {
                var value = (CCBValue)pKeyframe1.Value;
                return(new CCBRotateTo(duration, value.GetFloatValue()));
            }

            case "opacity":
            {
                var value = (CCBValue)pKeyframe1.Value;
                return(new CCFadeTo(duration, value.GetByteValue()));
            }

            case "color":
            {
                var       color = (CCColor3BWapper)pKeyframe1.Value;
                CCColor3B c     = color.Color;

                return(new CCTintTo(duration, c.R, c.G, c.B));
            }

            case "visible":
            {
                var value = (CCBValue)pKeyframe1.Value;
                if (value.GetBoolValue())
                {
                    return(new CCSequence(new CCDelayTime(duration), new CCShow()));
                }
                return(new CCSequence(new CCDelayTime(duration), new CCHide()));
            }

            case "displayFrame":
                return(new CCSequence(new CCDelayTime(duration), new CCBSetSpriteFrame((CCSpriteFrame)pKeyframe1.Value)));

            case "position":
            {
                // Get position type
                var array = (List <CCBValue>)GetBaseValue(node, pPropName);
                var type  = (CCBPositionType)array[2].GetIntValue();

                // Get relative position
                var   value = (List <CCBValue>)pKeyframe1.Value;
                float x     = value[0].GetFloatValue();
                float y     = value[1].GetFloatValue();

                CCSize containerSize = GetContainerSize(node.Parent);

                CCPoint absPos = CCBHelper.GetAbsolutePosition(new CCPoint(x, y), type, containerSize, pPropName);

                return(new CCMoveTo(duration, absPos));
            }

            case "scale":
            {
                // Get position type
                var array = (List <CCBValue>)GetBaseValue(node, pPropName);
                var type  = (CCBScaleType)array[2].GetIntValue();

                // Get relative scale
                var   value = (List <CCBValue>)pKeyframe1.Value;
                float x     = value[0].GetFloatValue();
                float y     = value[1].GetFloatValue();

                if (type == CCBScaleType.MultiplyResolution)
                {
                    float resolutionScale = CCBReader.ResolutionScale;
                    x *= resolutionScale;
                    y *= resolutionScale;
                }

                return(new CCScaleTo(duration, x, y));
            }

            case "skew":
            {
                // Get relative skew
                var   value = (List <CCBValue>)pKeyframe1.Value;
                float x     = value[0].GetFloatValue();
                float y     = value[1].GetFloatValue();

                return(new CCSkewTo(duration, x, y));
            }

            default:
                CCLog.Log("CCBReader: Failed to create animation for property: {0}", pPropName);
                break;
            }

            return(null);
        }
Exemplo n.º 14
0
		private void SetAnimatedProperty(string pPropName, CCNode node, object pValue, float fTweenDuraion)
		{
			if (fTweenDuraion > 0)
			{
				// Create a fake keyframe to generate the action from
				var kf1 = new CCBKeyframe();
				kf1.Value = pValue;
				kf1.Time = fTweenDuraion;
				kf1.EasingType = CCBEasingType.Linear;

				// Animate
				CCFiniteTimeAction tweenAction = GetAction(null, kf1, pPropName, node);
				node.RunAction(tweenAction);
			}
			else
			{
				// Just set the value

				if (pPropName == "position")
				{
					// Get position type
					var array = (List<CCBValue>)GetBaseValue(node, pPropName);
					var type = (CCBPositionType)array[2].GetIntValue();

					// Get relative position
					var value = (List<CCBValue>)pValue;
					float x = value[0].GetFloatValue();
					float y = value[1].GetFloatValue();

					node.Position = CCBHelper.GetAbsolutePosition(new CCPoint(x, y), type, GetContainerSize(node.Parent), pPropName);
				}
				else if (pPropName == "scale")
				{
					// Get scale type
					var array = (List<CCBValue>)GetBaseValue(node, pPropName);
					var type = (CCBScaleType)array[2].GetIntValue();

					// Get relative scale
					var value = (List<CCBValue>)pValue;
					float x = value[0].GetFloatValue();
					float y = value[1].GetFloatValue();

					CCBHelper.SetRelativeScale(node, x, y, type, pPropName);
				}
				else if (pPropName == "skew")
				{
					// Get relative scale
					var value = (List<CCBValue>)pValue;
					float x = value[0].GetFloatValue();
					float y = value[1].GetFloatValue();

					node.SkewX = x;
					node.SkewY = y;
				}
				else
				{
					// [node setValue:value forKey:name];

					// TODO only handle rotation, opacity, displayFrame, color
					if (pPropName == "rotation")
					{
						float rotate = ((CCBValue)pValue).GetFloatValue();
						node.Rotation = rotate;
					}
					else if (pPropName == "rotationX")
					{
						float rotate = ((CCBValue)pValue).GetFloatValue();
						node.RotationX = rotate;
					}
					else if (pPropName == "rotationY")
					{
						float rotate = ((CCBValue)pValue).GetFloatValue();
						node.RotationY = rotate;
					}
					else if (pPropName == "opacity")
					{
						byte opacity = ((CCBValue)pValue).GetByteValue();
						node.Opacity = opacity;
					}
					else if (pPropName == "displayFrame")
					{
						((CCSprite)node).SpriteFrame = (CCSpriteFrame)pValue;
					}
					else if (pPropName == "color")
					{
						var color = (CCColor3BWapper)pValue;
						node.Color = color.Color;
					}
					else if (pPropName == "visible")
					{
						bool visible = ((CCBValue)pValue).GetBoolValue();
						node.Visible = visible;
					}
					else
					{
						CCLog.Log("unsupported property name is {0}", pPropName);
						Debug.Assert(false, "unsupported property now");
					}
				}
			}
		}
Exemplo n.º 15
0
		private CCFiniteTimeAction GetAction(CCBKeyframe pKeyframe0, CCBKeyframe pKeyframe1, string pPropName, CCNode node)
		{
			float duration = pKeyframe1.Time - (pKeyframe0 != null ? pKeyframe0.Time : 0);

			switch (pPropName)
			{
				case "rotationX":
					{
						CCBValue value = (CCBValue)pKeyframe1.Value;
						return new CCBRotateXTo(duration, value.GetFloatValue());
					}
				case "rotationY":
					{
						CCBValue value = (CCBValue)pKeyframe1.Value;
						return new CCBRotateYTo(duration, value.GetFloatValue());
					}
				case "rotation":
					{
						var value = (CCBValue)pKeyframe1.Value;
						return new CCBRotateTo(duration, value.GetFloatValue());
					}
				case "opacity":
					{
						var value = (CCBValue)pKeyframe1.Value;
						return new CCFadeTo(duration, value.GetByteValue());
					}
				case "color":
					{
						var color = (CCColor3BWapper)pKeyframe1.Value;
						CCColor3B c = color.Color;

						return new CCTintTo(duration, c.R, c.G, c.B);
					}
				case "visible":
					{
						var value = (CCBValue)pKeyframe1.Value;
						if (value.GetBoolValue())
						{
							return new CCSequence(new CCDelayTime(duration), new CCShow());
						}
						return new CCSequence(new CCDelayTime(duration), new CCHide());
					}
				case "displayFrame":
					return new CCSequence(new CCDelayTime(duration), new CCBSetSpriteFrame((CCSpriteFrame)pKeyframe1.Value));
				case "position":
					{
						// Get position type
						var array = (List<CCBValue>)GetBaseValue(node, pPropName);
						var type = (CCBPositionType)array[2].GetIntValue();

						// Get relative position
						var value = (List<CCBValue>)pKeyframe1.Value;
						float x = value[0].GetFloatValue();
						float y = value[1].GetFloatValue();

						CCSize containerSize = GetContainerSize(node.Parent);

						CCPoint absPos = CCBHelper.GetAbsolutePosition(new CCPoint(x, y), type, containerSize, pPropName);

						return new CCMoveTo(duration, absPos);
					}
				case "scale":
					{
						// Get position type
						var array = (List<CCBValue>)GetBaseValue(node, pPropName);
						var type = (CCBScaleType)array[2].GetIntValue();

						// Get relative scale
						var value = (List<CCBValue>)pKeyframe1.Value;
						float x = value[0].GetFloatValue();
						float y = value[1].GetFloatValue();

						if (type == CCBScaleType.MultiplyResolution)
						{
							float resolutionScale = CCBReader.ResolutionScale;
							x *= resolutionScale;
							y *= resolutionScale;
						}

						return new CCScaleTo(duration, x, y);
					}
				case "skew":
					{
						// Get relative skew
						var value = (List<CCBValue>)pKeyframe1.Value;
						float x = value[0].GetFloatValue();
						float y = value[1].GetFloatValue();

						return new CCSkewTo(duration, x, y);
					}
				default:
					CCLog.Log("CCBReader: Failed to create animation for property: {0}", pPropName);
					break;
			}

			return null;
		}