private 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(
                        "cocos2d: CCAnimationCache: Animation '%s' 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.SpriteFrameByName(spriteFrameName);

                    if (spriteFrame == null)
                    {
                        CCLog.Log(
                            "cocos2d: CCAnimationCache: Animation '%s' refers to frame '%s' 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();
                    animFrame.InitWithSpriteFrame(spriteFrame, delayUnits, userInfo);

                    array.Add(animFrame);
                }

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

                animation.RestoreOriginalFrame = restoreOriginalFrame;

                SharedAnimationCache.AddAnimation(animation, name);
            }
        }
Exemple #2
0
 public static CCAnimation Create(List<CCAnimationFrame> arrayOfAnimationFrameNames, float delayPerUnit, uint loops)
 {
     var pAnimation = new CCAnimation();
     pAnimation.InitWithAnimationFrames(arrayOfAnimationFrameNames, delayPerUnit, loops);
     return pAnimation;
 }