示例#1
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;
        }
示例#2
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);
        }
示例#3
0
        protected virtual bool ParsePropTypeCheck(CCNode node, CCNode parent, CCBReader reader, string propertyName)
        {
            bool ret = reader.ReadBool();

            if (reader.AnimatedProperties.Contains(propertyName))
            {
                CCBValue value = new CCBValue(ret);
                reader.AnimationManager.SetBaseValue(value, node, propertyName);
            }

            return ret;
        }
        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);
        }
示例#5
0
        protected virtual float ParsePropTypeDegrees(CCNode node, CCNode parent, CCBReader reader, string propertyName)
        {
            float ret = reader.ReadFloat();
            if (reader.AnimatedProperties.Contains(propertyName))
            {
                CCBValue value = new CCBValue(ret);
                reader.AnimationManager.SetBaseValue(value, node, propertyName);
            }

            return ret;
        }