Beispiel #1
0
        void ParseVersion2(PlistDictionary animations)
        {
            CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache;

            foreach (var pElement in animations)
            {
                string          name          = pElement.Key;
                PlistDictionary animationDict = pElement.Value.AsDictionary;

                int  loops = animationDict["loops"].AsInt;
                bool restoreOriginalFrame = animationDict["restoreOriginalFrame"].AsBool;

                PlistArray frameArray = animationDict["frames"].AsArray;

                if (frameArray == null)
                {
                    CCLog.Log(
                        "CocosSharp: CCAnimationCache: Animation '{0}' found in dictionary without any frames - cannot add to animation cache.",
                        name);
                    continue;
                }

                // Array of AnimationFrames
                var array = new List <CCAnimationFrame>(frameArray.Count);

                foreach (PlistObjectBase pObj in frameArray)
                {
                    PlistDictionary entry = pObj.AsDictionary;

                    string        spriteFrameName = entry["spriteframe"].AsString;
                    CCSpriteFrame spriteFrame     = frameCache[spriteFrameName];

                    if (spriteFrame == null)
                    {
                        CCLog.Log(
                            "cocos2d: CCAnimationCache: Animation '{0}' refers to frame '{1}' which is not currently in the CCSpriteFrameCache. This frame will not be added to the animation.",
                            name, spriteFrameName);

                        continue;
                    }

                    float           delayUnits = entry["delayUnits"].AsFloat;
                    PlistDictionary userInfo   = entry["notification"].AsDictionary;

                    var animFrame = new CCAnimationFrame(spriteFrame, delayUnits, userInfo);

                    array.Add(animFrame);
                }

                float delayPerUnit = animationDict["delayPerUnit"].AsFloat;
                var   animation    = new CCAnimation(array, delayPerUnit, (uint)loops);

                animation.RestoreOriginalFrame = restoreOriginalFrame;

                this.AddAnimation(animation, name);
            }
        }
Beispiel #2
0
        void ParseVersion1(PlistDictionary animations)
        {
            CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache;

            foreach (var pElement in animations)
            {
                PlistDictionary animationDict = pElement.Value.AsDictionary;

                PlistArray frameNames = animationDict["frames"].AsArray;
                float      delay      = animationDict["delay"].AsFloat;

                if (frameNames == null)
                {
                    CCLog.Log(
                        "CocosSharp: CCAnimationCache: Animation '{0}' found in dictionary without any frames - cannot add to animation cache.",
                        pElement.Key);
                    continue;
                }

                var frames = new List <CCAnimationFrame>(frameNames.Count);

                foreach (PlistObjectBase pObj in frameNames)
                {
                    string        frameName   = pObj.AsString;
                    CCSpriteFrame spriteFrame = frameCache[frameName];

                    if (spriteFrame == null)
                    {
                        CCLog.Log(
                            "cocos2d: CCAnimationCache: Animation '{0}' refers to frame '%s' which is not currently in the CCSpriteFrameCache. This frame will not be added to the animation.",
                            pElement.Key, frameName);
                        continue;
                    }

                    var animFrame = new CCAnimationFrame(spriteFrame, 1, null);
                    frames.Add(animFrame);
                }

                if (frames.Count == 0)
                {
                    CCLog.Log(
                        "CocosSharp: CCAnimationCache: None of the frames for animation '{0}' were found in the CCSpriteFrameCache. Animation is not being added to the Animation Cache.",
                        pElement.Key);
                    continue;
                }
                else if (frames.Count != frameNames.Count)
                {
                    CCLog.Log(
                        "CocosSharp: CCAnimationCache: An animation in your dictionary refers to a frame which is not in the CCSpriteFrameCache. Some or all of the frames for the animation '{0}' may be missing.",
                        pElement.Key);
                }

                CCAnimation animation = new CCAnimation(frames, delay, 1);

                this.AddAnimation(animation, pElement.Key);
            }
        }
Beispiel #3
0
        public void AddSpriteFrame(CCSpriteFrame frame)
        {
            var animFrame = new CCAnimationFrame(frame, 1.0f, null);

            Frames.Add(animFrame);

            // update duration
            TotalDelayUnits++;
        }
Beispiel #4
0
        public void AddSpriteFrame(CCSpriteFrame frame)
        {
            var animFrame = new CCAnimationFrame(frame, 1.0f, null);
            Frames.Add(animFrame);

            // update duration
            TotalDelayUnits++;
        }
        void ParseVersion2(PlistDictionary animations)
        {
            CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache;

            foreach (var pElement in animations)
            {
                string name = pElement.Key;
                PlistDictionary animationDict = pElement.Value.AsDictionary;

                int loops = animationDict["loops"].AsInt;
                bool restoreOriginalFrame = animationDict["restoreOriginalFrame"].AsBool;

                PlistArray frameArray = animationDict["frames"].AsArray;

                if (frameArray == null)
                {
                    CCLog.Log(
                        "CocosSharp: CCAnimationCache: Animation '{0}' found in dictionary without any frames - cannot add to animation cache.",
                        name);
                    continue;
                }

                // Array of AnimationFrames
                var array = new List<CCAnimationFrame>(frameArray.Count);

                foreach (PlistObjectBase pObj in frameArray)
                {
                    PlistDictionary entry = pObj.AsDictionary;

                    string spriteFrameName = entry["spriteframe"].AsString;
                    CCSpriteFrame spriteFrame = frameCache[spriteFrameName];

                    if (spriteFrame == null)
                    {
                        CCLog.Log(
                            "cocos2d: CCAnimationCache: Animation '{0}' refers to frame '{1}' which is not currently in the CCSpriteFrameCache. This frame will not be added to the animation.",
                            name, spriteFrameName);

                        continue;
                    }

                    float delayUnits = entry["delayUnits"].AsFloat;
                    PlistDictionary userInfo = entry["notification"].AsDictionary;

                    var animFrame = new CCAnimationFrame(spriteFrame, delayUnits, userInfo);

                    array.Add(animFrame);
                }

                float delayPerUnit = animationDict["delayPerUnit"].AsFloat;
                var animation = new CCAnimation(array, delayPerUnit, (uint) loops);

                animation.RestoreOriginalFrame = restoreOriginalFrame;

                this.AddAnimation(animation, name);
            }
        }
        void ParseVersion1(PlistDictionary animations)
        {
            CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache;

            foreach (var pElement in animations)
            {
                PlistDictionary animationDict = pElement.Value.AsDictionary;

                PlistArray frameNames = animationDict["frames"].AsArray;
                float delay = animationDict["delay"].AsFloat;

                if (frameNames == null)
                {
                    CCLog.Log(
                        "CocosSharp: CCAnimationCache: Animation '{0}' found in dictionary without any frames - cannot add to animation cache.",
                        pElement.Key);
                    continue;
                }

                var frames = new List<CCAnimationFrame>(frameNames.Count);

                foreach (PlistObjectBase pObj in frameNames)
                {
                    string frameName = pObj.AsString;
                    CCSpriteFrame spriteFrame = frameCache[frameName];

                    if (spriteFrame == null)
                    {
                        CCLog.Log(
                            "cocos2d: CCAnimationCache: Animation '{0}' refers to frame '%s' which is not currently in the CCSpriteFrameCache. This frame will not be added to the animation.",
                            pElement.Key, frameName);
                        continue;
                    }

                    var animFrame = new CCAnimationFrame(spriteFrame, 1, null);
                    frames.Add(animFrame);
                }

                if (frames.Count == 0)
                {
                    CCLog.Log(
                        "CocosSharp: CCAnimationCache: None of the frames for animation '{0}' were found in the CCSpriteFrameCache. Animation is not being added to the Animation Cache.",
                        pElement.Key);
                    continue;
                }
                else if (frames.Count != frameNames.Count)
                {
                    CCLog.Log(
                        "CocosSharp: CCAnimationCache: An animation in your dictionary refers to a frame which is not in the CCSpriteFrameCache. Some or all of the frames for the animation '{0}' may be missing.",
                        pElement.Key);
                }

                CCAnimation animation = new CCAnimation(frames, delay, 1);

                this.AddAnimation(animation, pElement.Key);
            }
        }