spriteFrameByName() public method

public spriteFrameByName ( string name ) : CCSpriteFrame
name string
return CCSpriteFrame
        void parseVersion1(NSDictionary animations)
        {
            CCSpriteFrameCache frameCache = CCSpriteFrameCache.sharedSpriteFrameCache;

            var enumerator = animations.GetEnumerator();

            while (enumerator.MoveNext())
            {
                KeyValuePair <object, object> kv = enumerator.Current;
                string       name          = (string)kv.Key;
                NSDictionary animationDict = (NSDictionary)kv.Value;
                ArrayList    frameNames    = (ArrayList)animationDict["frames"];
                float        delay         = (float)animationDict["delay"];
                CCAnimation  animation     = null;

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

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

                var framesEnumerator = frameNames.GetEnumerator();
                while (framesEnumerator.MoveNext())
                {
                    string        frameName   = (string)framesEnumerator.Current;
                    CCSpriteFrame spriteFrame = frameCache.spriteFrameByName(frameName);

                    if (spriteFrame == null)
                    {
                        CCDebug.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, frameName);

                        continue;
                    }

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

                if (frames.Count == 0)
                {
                    CCDebug.Log("cocos2d: CCAnimationCache: None of the frames for animation '{0}' were found in the CCSpriteFrameCache. Animation is not being added to the Animation Cache.", name);
                    continue;
                }
                else if (frames.Count != frameNames.Count)
                {
                    CCDebug.Log("cocos2d: 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.", name);
                }

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

                CCAnimationCache.sharedAnimationCache.addAnimation(animation, name);
            }
        }
        void parseVersion2(NSDictionary animations)
        {
            CCSpriteFrameCache frameCache = CCSpriteFrameCache.sharedSpriteFrameCache;

            var enumerator = animations.GetEnumerator();

            while (enumerator.MoveNext())
            {
                KeyValuePair <object, object> kv = enumerator.Current;
                string       name          = (string)kv.Key;
                NSDictionary animationDict = (NSDictionary)kv.Value;

                int    loops    = 0;
                object loopsObj = loops;
                if (!animationDict.TryGetValue("loops", out loopsObj))
                {
                    loops = 1;
                }
                else
                {
                    loops = (int)loopsObj;
                }
                bool    restoreOriginalFrame = (bool)animationDict["restoreOriginalFrame"];
                NSArray frameArray           = (NSArray)animationDict["frames"];


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

                // Array of AnimationFrames
                List <CCAnimationFrame> array = new List <CCAnimationFrame>(frameArray.Count);
                var frameArrayEnumerator      = frameArray.GetEnumerator();
                while (frameArrayEnumerator.MoveNext())
                {
                    NSDictionary  entry           = (NSDictionary)frameArrayEnumerator.Current;
                    string        spriteFrameName = (string)entry["spriteframe"];
                    CCSpriteFrame spriteFrame     = frameCache.spriteFrameByName(spriteFrameName);

                    if (spriteFrame == null)
                    {
                        CCDebug.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 = float.Parse(entry["delayUnits"].ToString());
                    NSDictionary userInfo   = entry.objectForKey <NSDictionary>("notification");

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

                    array.Add(animFrame);
                }

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

                animation.restoreOriginalFrame = restoreOriginalFrame;

                CCAnimationCache.sharedAnimationCache.addAnimation(animation, name);
            }
        }