protected override CCAction reverseImpl()
        {
            List <CCAnimationFrame> oldArray = _animation.frames;
            List <CCAnimationFrame> newArray = new List <CCAnimationFrame> (oldArray.Count);

            var enumerator = oldArray.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var frame = enumerator.Current;
                newArray.Add(frame.copy());
            }
            newArray.Reverse();


            CCAnimation newAnim = new CCAnimation(newArray, _animation.delayPerUnit, _animation.loops);

            newAnim.restoreOriginalFrame = _animation.restoreOriginalFrame;
            CCAnimate animate = new CCAnimate(animation);

            return(animate);
        }
Exemple #2
0
        /** Returns a CCAnimation that was previously added.
         * If the name is not found it will return nil.
         * You should retain the returned copy if you are going to use it.
         */
        public CCAnimation animationByName(string name)
        {
            CCAnimation anim = _animations [name] as CCAnimation;

            return(anim);
        }
Exemple #3
0
 /** Adds a CCAnimation with a name.*/
 public void addAnimation(CCAnimation animation, string name)
 {
     _animations.Add(name, animation);
 }
Exemple #4
0
        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);
            }
        }
 /** creates the action with an Animation and will restore the original frame when the animation is over */
 public CCAnimate(CCAnimation animation)
 {
     initWithAnimation(animation);
 }