Beispiel #1
0
        public override CCFiniteTimeAction Reverse()
        {
            var pOldArray = m_pAnimation.Frames;
            var pNewArray = new List<CCAnimationFrame>(pOldArray.Count);

            //TODO: CCARRAY_VERIFY_TYPE(pOldArray, CCAnimationFrame*);

            if (pOldArray.Count > 0)
            {
                for (int i = pOldArray.Count - 1; i >= 0; i--)
                {
                    var pElement = (CCAnimationFrame)pOldArray[i];
                    if (pElement == null)
                    {
                        break;
                    }

                    pNewArray.Add(pElement.Copy() as CCAnimationFrame);
                }
            }

            var newAnim = new CCAnimation(pNewArray, m_pAnimation.DelayPerUnit, m_pAnimation.Loops);
            newAnim.RestoreOriginalFrame = m_pAnimation.RestoreOriginalFrame;
            return new CCAnimate (newAnim);
        }
Beispiel #2
0
        public static CCAnimation Create()
        {
            var pAnimation = new CCAnimation();
            pAnimation.Init();

            return pAnimation;
        }
Beispiel #3
0
        public static CCAnimation Create(List<CCSpriteFrame> frames, float delay)
        {
            var pAnimation = new CCAnimation();
            pAnimation.InitWithSpriteFrames(frames, delay);

            return pAnimation;
        }
Beispiel #4
0
        public static CCAnimate actionWithAnimation(CCAnimation pAnimation)
        {
            CCAnimate pAnimate = new CCAnimate();
            pAnimate.initWithAnimation(pAnimation, true);

            return pAnimate;
        }
Beispiel #5
0
        public static CCAnimate actionWithAnimation(CCAnimation pAnimation, bool bRestoreOriginalFrame)
        {
            CCAnimate pAnimate = new CCAnimate();
            pAnimate.initWithAnimation(pAnimation, bRestoreOriginalFrame);

            return pAnimate;
        }
 public void AddAnimation(CCAnimation animation, string name)
 {
     if (!m_pAnimations.ContainsKey(name))
     {
         m_pAnimations.Add(name, animation);
     }
 }
Beispiel #7
0
        public static CCAnimate actionWithDuration(float duration, CCAnimation pAnimation, bool bRestoreOriginalFrame)
        {
            CCAnimate pAnimate = new CCAnimate();
            pAnimate.initWithDuration(duration, pAnimation, bRestoreOriginalFrame);

            return pAnimate;
        }
        public SpriteBatchNodeChildren()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            // parents
            CCSpriteBatchNode batch = new CCSpriteBatchNode("animations/grossini", 50);

            AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/grossini.plist");

            CCSprite sprite1 = new CCSprite("grossini_dance_01.png");
            sprite1.Position = (new CCPoint(s.Width / 3, s.Height / 2));

            CCSprite sprite2 = new CCSprite("grossini_dance_02.png");
            sprite2.Position = (new CCPoint(50, 50));

            CCSprite sprite3 = new CCSprite("grossini_dance_03.png");
            sprite3.Position = (new CCPoint(-50, -50));

            batch.AddChild(sprite1);
            sprite1.AddChild(sprite2);
            sprite1.AddChild(sprite3);

            // BEGIN NEW CODE
            var animFrames = new List<CCSpriteFrame>();
            string str = "";
            for (int i = 1; i < 15; i++)
            {
                string temp = "";
                if (i<10)
                {
                    temp = "0" + i;
                }
                else
                {
                    temp = i.ToString();
                }
                str = string.Format("grossini_dance_{0}.png", temp);
                CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache.SpriteFrameByName(str);
                animFrames.Add(frame);
            }

            CCAnimation animation = new CCAnimation(animFrames, 0.2f);
            sprite1.RunAction(new CCRepeatForever (new CCAnimate (animation)));
            // END NEW CODE

            CCActionInterval action = new CCMoveBy (2, new CCPoint(200, 0));
            CCActionInterval action_back = (CCActionInterval)action.Reverse();
            CCActionInterval action_rot = new CCRotateBy (2, 360);
            CCActionInterval action_s = new CCScaleBy(2, 2);
            CCActionInterval action_s_back = (CCActionInterval)action_s.Reverse();

            CCActionInterval seq2 = (CCActionInterval)action_rot.Reverse();
            sprite2.RunAction(new CCRepeatForever (seq2));

            sprite1.RunAction((CCAction)(new CCRepeatForever (action_rot)));
            sprite1.RunAction((CCAction)(new CCRepeatForever ((CCActionInterval)(CCSequence.FromActions(action, action_back)))));
            sprite1.RunAction((CCAction)(new CCRepeatForever ((CCActionInterval)(CCSequence.FromActions(action_s, action_s_back)))));
        }
        /** Creates an animation with frames.
        @since v0.99.5
        */
        public static CCAnimation animationWithFrames(List<CCSpriteFrame> frames)
        {
            CCAnimation pAnimation = new CCAnimation();
            pAnimation.initWithFrames(frames);
            // pAnimation->autorelease();

            return pAnimation;
        }
Beispiel #10
0
        /** Creates an animation
        @since v0.99.5
        */
        public static CCAnimation animation()
        {
            CCAnimation pAnimation = new CCAnimation();
            pAnimation.init();
            // pAnimation->autorelease();

            return pAnimation;
        }
        public SpriteOffsetAnchorRotation()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;
            CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
            cache.AddSpriteFramesWithFile("animations/grossini.plist");
            cache.AddSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray");

            for (int i = 0; i < 3; i++)
            {
                //
                // Animation using Sprite BatchNode
                //
                CCSprite sprite = new CCSprite("grossini_dance_01.png");
                sprite.Position = (new CCPoint(s.Width / 4 * (i + 1), s.Height / 2));

                CCSprite point = new CCSprite("Images/r1");
                point.Scale = 0.25f;
                point.Position = (sprite.Position);
                AddChild(point, 1);

                switch (i)
                {
                    case 0:
                        sprite.AnchorPoint = new CCPoint(0, 0);
                        break;
                    case 1:
                        sprite.AnchorPoint = new CCPoint(0.5f, 0.5f);
                        break;
                    case 2:
                        sprite.AnchorPoint = new CCPoint(1, 1);
                        break;
                }

                point.Position = sprite.Position;

                var animFrames = new List<CCSpriteFrame>(14);
                string str = "";
                for (int j = 0; j < 14; j++)
                {
                    str = string.Format("grossini_dance_{0:00}.png", j + 1);
                    CCSpriteFrame frame = cache.SpriteFrameByName(str);
                    animFrames.Add(frame);
                }

                CCAnimation animation = new CCAnimation(animFrames, 0.3f);
                sprite.RunAction(new CCRepeatForever (new CCAnimate (animation)));
                sprite.RunAction(new CCRepeatForever (new CCRotateBy (10, 360)));

                AddChild(sprite, 0);

                //animFrames.release();    // win32 : memory leak    2010-0415
            }
        }
Beispiel #12
0
        public override void OnEnter()
        {
            base.OnEnter();

            centerSprites(3);

            //
            // Manual animation
            //
            var animation = new CCAnimation();
            for (var i = 1; i < 15; i++)
            {
                var szName = String.Format("Images/grossini_dance_{0:00}", i);
                animation.AddSpriteFrameWithFileName(szName);
            }

            // should last 2.8 seconds. And there are 14 frames.
            animation.DelayPerUnit = 2.8f / 14.0f;
            animation.RestoreOriginalFrame = true;

            var action = new CCAnimate (animation);
            m_grossini.RunAction(CCSequence.FromActions(action, action.Reverse()));

            //
            // File animation
            //
            // With 2 loops and reverse
            var cache = CCAnimationCache.SharedAnimationCache;
            cache.AddAnimationsWithFile("animations/animations-2.plist");
            var animation2 = cache.AnimationByName("dance_1");

            var action2 = new CCAnimate (animation2);
            m_tamara.RunAction(CCSequence.FromActions(action2, action2.Reverse()));

            // TODO:
            //     observer_ = [[NSNotificationCenter defaultCenter] addObserverForName:CCAnimationFrameDisplayedNotification object:nil queue:nil usingBlock:^(NSNotification* notification) {
            //
            //         NSDictionary *userInfo = [notification userInfo];
            //         NSLog(@"object %@ with data %@", [notification object], userInfo );
            //     }];

            //
            // File animation
            //
            // with 4 loops
            var animation3 = (CCAnimation) animation2.Copy();
            animation3.Loops = 4;

            var action3 = new CCAnimate (animation3);
            m_kathia.RunAction(action3);
        }
        public override void OnEnter()
        {
            base.OnEnter();
            CCSize s = CCDirector.SharedDirector.WinSize;

            // IMPORTANT:
            // The sprite frames will be cached AND RETAINED, and they won't be released unless you call
            //     [[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
            //
            // CCSpriteFrameCache is a cache of CCSpriteFrames
            // CCSpriteFrames each contain a texture id and a rect (frame).

            CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
            cache.AddSpriteFramesWithFile("animations/grossini-aliases.plist", "animations/grossini-aliases");

            //
            // Animation using Sprite batch
            //
            // A CCSpriteBatchNode can reference one and only one texture (one .png file)
            // Sprites that are contained in that texture can be instantiatied as CCSprites and then added to the CCSpriteBatchNode
            // All CCSprites added to a CCSpriteBatchNode are drawn in one OpenGL ES draw call
            // If the CCSprites are not added to a CCSpriteBatchNode then an OpenGL ES draw call will be needed for each one, which is less efficient
            //
            // When you animate a sprite, CCAnimation changes the frame of the sprite using setDisplayFrame: (this is why the animation must be in the same texture)
            // When setDisplayFrame: is used in the CCAnimation it changes the frame to one specified by the CCSpriteFrames that were added to the animation,
            // but texture id is still the same and so the sprite is still a child of the CCSpriteBatchNode,
            // and therefore all the animation sprites are also drawn as part of the CCSpriteBatchNode
            //

            CCSprite sprite = new CCSprite("grossini_dance_01.png");
            sprite.Position = (new CCPoint(s.Width * 0.5f, s.Height * 0.5f));

            CCSpriteBatchNode spriteBatch = new CCSpriteBatchNode("animations/grossini-aliases");
            spriteBatch.AddChild(sprite);
            AddChild(spriteBatch);

            var animFrames = new List<CCSpriteFrame>(15);
            string str = "";
            for (int i = 1; i < 15; i++)
            {
                // Obtain frames by alias name
                str = string.Format("dance_{0:00}", i);
                CCSpriteFrame frame = cache.SpriteFrameByName(str);
                animFrames.Add(frame);
            }

            CCAnimation animation = new CCAnimation(animFrames, 0.3f);
            // 14 frames * 1sec = 14 seconds
            sprite.RunAction(new CCRepeatForever (new CCAnimate (animation)));
        }
Beispiel #14
0
        public bool initWithAnimation(CCAnimation pAnimation, bool bRestoreOriginalFrame)
        {
            Debug.Assert(pAnimation != null);

            if (base.initWithDuration(pAnimation.getFrames().Count * pAnimation.getDelay()))
            {
                m_bRestoreOriginalFrame = bRestoreOriginalFrame;
                m_pAnimation = pAnimation;
                m_pOrigFrame = null;

                return true;
            }

            return false;
        }
Beispiel #15
0
        public bool initWithDuration(float duration, CCAnimation pAnimation, bool bRestoreOriginalFrame)
        {
            Debug.Assert(pAnimation != null);

            if (base.initWithDuration(duration))
            {
                m_bRestoreOriginalFrame = bRestoreOriginalFrame;
                m_pAnimation            = pAnimation;
                m_pOrigFrame            = null;

                return(true);
            }

            return(false);
        }
Beispiel #16
0
        public bool initWithAnimation(CCAnimation pAnimation, bool bRestoreOriginalFrame)
        {
            Debug.Assert(pAnimation != null);

            if (base.initWithDuration(pAnimation.getFrames().Count *pAnimation.getDelay()))
            {
                m_bRestoreOriginalFrame = bRestoreOriginalFrame;
                m_pAnimation            = pAnimation;
                m_pOrigFrame            = null;

                return(true);
            }

            return(false);
        }
Beispiel #17
0
        public bool initWithDuration(float duration, CCAnimation pAnimation, bool bRestoreOriginalFrame)
        {
            Debug.Assert(pAnimation != null);

            if (base.initWithDuration(duration))
            {
                m_bRestoreOriginalFrame = bRestoreOriginalFrame;
                m_pAnimation = pAnimation;
                m_pOrigFrame = null;

                return true;
            }

            return false;
        }
        public CCAnimate CreateAnimateAction()
        {
            var frameList = new List<CCSpriteFrame>();

            for (var i = 0; i < 7; i++)
            {
                var texture = CreateCharacterTexture();

                var sprite = new CCSpriteFrame(texture, new CCRect(0, 0, texture.ContentSize.Width, texture.ContentSize.Height));
                frameList.Add(sprite);
            }
            var animation = new CCAnimation(frameList, 0.1f);
            var animate = new CCAnimate (animation);

            return animate;
        }
Beispiel #19
0
        public override CCFiniteTimeAction reverse()
        {
            List <CCSpriteFrame> list   = this.m_pAnimation.getFrames();
            List <CCSpriteFrame> frames = new List <CCSpriteFrame>(list.Count);

            if (list.Count > 0)
            {
                for (int i = list.Count - 1; i >= 0; i--)
                {
                    CCSpriteFrame frame = list[i];
                    if (frame == null)
                    {
                        break;
                    }
                    frames.Insert((list.Count - 1) - i, (CCSpriteFrame)frame.copy());
                }
            }
            CCAnimation pAnimation = CCAnimation.animationWithFrames(frames, this.m_pAnimation.getDelay());

            return(actionWithDuration(base.m_fDuration, pAnimation, this.m_bRestoreOriginalFrame));
        }
        public SpriteAnimationSplit()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage("animations/dragon_animation");

            // manually add frames to the frame cache
            CCSpriteFrame frame0 = new CCSpriteFrame(texture, new CCRect(132 * 0, 132 * 0, 132, 132));
            CCSpriteFrame frame1 = new CCSpriteFrame(texture, new CCRect(132 * 1, 132 * 0, 132, 132));
            CCSpriteFrame frame2 = new CCSpriteFrame(texture, new CCRect(132 * 2, 132 * 0, 132, 132));
            CCSpriteFrame frame3 = new CCSpriteFrame(texture, new CCRect(132 * 3, 132 * 0, 132, 132));
            CCSpriteFrame frame4 = new CCSpriteFrame(texture, new CCRect(132 * 0, 132 * 1, 132, 132));
            CCSpriteFrame frame5 = new CCSpriteFrame(texture, new CCRect(132 * 1, 132 * 1, 132, 132));

            //
            // Animation using Sprite BatchNode
            //
            CCSprite sprite = new CCSprite(frame0);
            sprite.Position = (new CCPoint(s.Width / 2 - 80, s.Height / 2));
            AddChild(sprite);

            var animFrames = new List<CCSpriteFrame>(6);
            animFrames.Add(frame0);
            animFrames.Add(frame1);
            animFrames.Add(frame2);
            animFrames.Add(frame3);
            animFrames.Add(frame4);
            animFrames.Add(frame5);

            CCAnimation animation = new CCAnimation(animFrames, 0.2f);
            CCAnimate animate = new CCAnimate (animation);
            CCActionInterval seq = (CCActionInterval)(CCSequence.FromActions(animate,
                               new CCFlipX(true),
                              (CCFiniteTimeAction)animate.Copy(),
                               new CCFlipX(false)
                               ));

            sprite.RunAction(new CCRepeatForever (seq));
            //animFrames->release();    // win32 : memory leak    2010-0415
        }
Beispiel #21
0
        public override CCFiniteTimeAction reverse()
        {
            List <CCSpriteFrame> pOldArray = m_pAnimation.getFrames();
            List <CCSpriteFrame> pNewArray = new List <CCSpriteFrame>(pOldArray.Count);

            if (pOldArray.Count > 0)
            {
                CCSpriteFrame pElement;
                for (int nIndex = pOldArray.Count - 1; nIndex >= 0; nIndex--)
                {
                    pElement = pOldArray[nIndex];
                    if (null == pElement)
                    {
                        break;
                    }

                    pNewArray.Insert(pOldArray.Count - 1 - nIndex, (CCSpriteFrame)(pElement.copy()));
                }
            }

            CCAnimation pNewAnim = CCAnimation.animationWithFrames(pNewArray, m_pAnimation.getDelay());

            return(CCAnimate.actionWithDuration(m_fDuration, pNewAnim, m_bRestoreOriginalFrame));
        }
Beispiel #22
0
        protected bool InitWithAnimation(CCAnimation pAnimation)
        {
            Debug.Assert(pAnimation != null);

            float singleDuration = pAnimation.Duration;

            if (base.InitWithDuration(singleDuration * pAnimation.Loops))
            {
                m_nNextFrame = 0;
                m_pAnimation = pAnimation;
                m_pOrigFrame = null;
                m_uExecutedLoops = 0;

                m_pSplitTimes.Capacity = pAnimation.Frames.Count;

                float accumUnitsOfTime = 0;
                float newUnitOfTimeValue = singleDuration / pAnimation.TotalDelayUnits;

                var pFrames = pAnimation.Frames;

                //TODO: CCARRAY_VERIFY_TYPE(pFrames, CCAnimationFrame *);

                foreach (var pObj in pFrames)
                {
                    var frame = (CCAnimationFrame) pObj;
                    float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration;
                    accumUnitsOfTime += frame.DelayUnits;
                    m_pSplitTimes.Add(value);
                }
                return true;
            }
            return false;
        }
        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);
            }
        }
Beispiel #24
0
        public AnimationCache()
        {
            var frameCache = CCSpriteFrameCache.SharedSpriteFrameCache;
            frameCache.AddSpriteFramesWithFile("animations/grossini.plist");
            frameCache.AddSpriteFramesWithFile("animations/grossini_gray.plist");
            frameCache.AddSpriteFramesWithFile("animations/grossini_blue.plist");

            //
            // create animation "dance"
            //
            var animFrames = new List<CCSpriteFrame>(15);
            string str = "";
            for (int i = 1; i < 15; i++)
            {
                str = string.Format("grossini_dance_{0:00}.png", i);
                CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache.SpriteFrameByName(str);
                animFrames.Add(frame);
            }

            CCAnimation animation = new CCAnimation(animFrames, 0.2f);

            // Add an animation to the Cache
            CCAnimationCache.SharedAnimationCache.AddAnimation(animation, "dance");

            //
            // create animation "dance gray"
            //
            animFrames.Clear();

            for (int i = 1; i < 15; i++)
            {
                str = String.Format("grossini_dance_gray_{0:00}.png", i);
                CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache.SpriteFrameByName(str);
                animFrames.Add(frame);
            }

            animation = new CCAnimation(animFrames, 0.2f);

            // Add an animation to the Cache
            CCAnimationCache.SharedAnimationCache.AddAnimation(animation, "dance_gray");

            //
            // create animation "dance blue"
            //
            animFrames.Clear();

            for (int i = 1; i < 4; i++)
            {
                str = String.Format("grossini_blue_{0:00}.png", i);
                CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache.SpriteFrameByName(str);
                animFrames.Add(frame);
            }

            animation = new CCAnimation(animFrames, 0.2f);

            // Add an animation to the Cache
            CCAnimationCache.SharedAnimationCache.AddAnimation(animation, "dance_blue");

            CCAnimationCache animCache = CCAnimationCache.SharedAnimationCache;

            CCAnimation normal = animCache.AnimationByName("dance");
            normal.RestoreOriginalFrame = true;
            CCAnimation dance_grey = animCache.AnimationByName("dance_gray");
            dance_grey.RestoreOriginalFrame = true;
            CCAnimation dance_blue = animCache.AnimationByName("dance_blue");
            dance_blue.RestoreOriginalFrame = true;

            CCAnimate animN = new CCAnimate (normal);
            CCAnimate animG = new CCAnimate (dance_grey);
            CCAnimate animB = new CCAnimate (dance_blue);

            CCFiniteTimeAction seq = CCSequence.FromActions(animN, animG, animB);

            // create an sprite without texture
            CCSprite grossini = new CCSprite();
            grossini.DisplayFrame = frameCache.SpriteFrameByName("grossini_dance_01.png");

            CCSize winSize = CCDirector.SharedDirector.WinSize;
            grossini.Position = (new CCPoint(winSize.Width / 2, winSize.Height / 2));
            AddChild(grossini);

            // run the animation
            grossini.RunAction(seq);
        }
Beispiel #25
0
 protected virtual void OnHandlePropTypeAnimation(CCNode node, CCNode parent, string propertyName, CCAnimation animation,
                                                  CCBReader reader)
 {
     CCLog.Log("Unexpected property type: '{0}'!", propertyName);
     Debug.Assert(false);
 }
Beispiel #26
0
        private 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;
                //CCAnimation* animation = NULL;

                if (frameNames == null)
                {
                    CCLog.Log(
                        "cocos2d: CCAnimationCache: Animation '%s' 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.SpriteFrameByName(frameName);

                    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.",
                            pElement.Key, frameName);
                        continue;
                    }

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

                if (frames.Count == 0)
                {
                    CCLog.Log(
                        "cocos2d: CCAnimationCache: None of the frames for animation '%s' 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(
                        "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 '%s' may be missing.",
                        pElement.Key);
                }

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

                SharedAnimationCache.AddAnimation(animation, pElement.Key);
            }
        }
Beispiel #27
0
        public object Copy(ICopyable pZone)
        {
            CCAnimation pCopy = null;
            if (pZone != null)
            {
                //in case of being called at sub class
                pCopy = (CCAnimation) (pZone);
            }
            else
            {
                pCopy = new CCAnimation();
            }

            pCopy.InitWithAnimationFrames(m_pFrames, m_fDelayPerUnit, m_uLoops);
            pCopy.RestoreOriginalFrame = m_bRestoreOriginalFrame;

            return pCopy;
        }
		/** 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 animation = new CCAnimation();
            if (m_pAnimations.TryGetValue(name, out animation))
            {
                return animation;
            }
            else
            {
                return null;
            }
        }
		/** Adds a CCAnimation with a name.
		*/
        public void addAnimation(CCAnimation animation, string name)
        { 
            m_pAnimations.Add(name, animation);
        }
Beispiel #30
0
        public bool initWithAnimation(CCAnimation pAnimation)
        {
            Debug.Assert(pAnimation != null);

            return(initWithAnimation(pAnimation, true));
        }
        public SpriteBatchNodeOffsetAnchorFlip()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            for (int i = 0; i < 3; i++)
            {
                CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
                cache.AddSpriteFramesWithFile("animations/grossini.plist");
                cache.AddSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray");

                //
                // Animation using Sprite batch
                //
                CCSprite sprite = new CCSprite("grossini_dance_01.png");
                sprite.Position = (new CCPoint(s.Width / 4 * (i + 1), s.Height / 2));

                CCSprite point = new CCSprite("Images/r1");
                point.Scale = 0.25f;
                point.Position = sprite.Position;
                AddChild(point, 200);

                switch (i)
                {
                    case 0:
                        sprite.AnchorPoint = new CCPoint(0, 0);
                        break;
                    case 1:
                        sprite.AnchorPoint = new CCPoint(0.5f, 0.5f);
                        break;
                    case 2:
                        sprite.AnchorPoint = (new CCPoint(1, 1));
                        break;
                }

                point.Position = sprite.Position;

                CCSpriteBatchNode spritebatch = new CCSpriteBatchNode("animations/grossini");
                AddChild(spritebatch);

                var animFrames = new List<CCSpriteFrame>();
                string tmp = "";
                for (int j = 0; j < 14; j++)
                {
                    string temp = "";
                    if ( i + 1<10)
                    {
                        temp = "0" + (i+1);
                    }
                    else
                    {
                        temp = (i + 1).ToString();
                    }
                    tmp = string.Format("grossini_dance_{0}.png", temp);
                    CCSpriteFrame frame = cache.SpriteFrameByName(tmp);
                    animFrames.Add(frame);
                }

                CCAnimation animation = new CCAnimation(animFrames, 0.3f);
                sprite.RunAction(new CCRepeatForever (new CCAnimate (animation)));

                animFrames = null;

                CCFlipY flip = new CCFlipY(true);
                CCFlipY flip_back = new CCFlipY(false);
                CCDelayTime delay = new CCDelayTime (1);
                CCFiniteTimeAction seq = CCSequence.FromActions((CCFiniteTimeAction)delay, (CCFiniteTimeAction)flip, (CCFiniteTimeAction)delay.Copy(null), (CCFiniteTimeAction)flip_back);
                sprite.RunAction(new CCRepeatForever ((CCActionInterval)seq));

                spritebatch.AddChild(sprite, i);
            }
        }
Beispiel #32
0
        public SpriteFrameTest()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            // IMPORTANT:
            // The sprite frames will be cached AND RETAINED, and they won't be released unless you call
            //     CCSpriteFrameCache::sharedSpriteFrameCache()->removeUnusedSpriteFrames);
            CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
            cache.AddSpriteFramesWithFile("animations/grossini.plist");
            cache.AddSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray");
            cache.AddSpriteFramesWithFile("animations/grossini_blue.plist", "animations/grossini_blue");

            //
            // Animation using Sprite BatchNode
            //
            m_pSprite1 = new CCSprite("grossini_dance_01.png");
            m_pSprite1.Position = (new CCPoint(s.Width / 2 -80, s.Height / 2));

            CCSpriteBatchNode spritebatch = new CCSpriteBatchNode("animations/grossini");
            spritebatch.AddChild(m_pSprite1);
            AddChild(spritebatch);

            var animFrames = new List<CCSpriteFrame>(15);

            string str = "";
            for (int i = 1; i < 15; i++)
            {
                str = string.Format("grossini_dance_{0:00}.png", i);
                CCSpriteFrame frame = cache.SpriteFrameByName(str);
                animFrames.Add(frame);
            }

            CCAnimation animation = new CCAnimation(animFrames, 0.3f);
            m_pSprite1.RunAction(new CCRepeatForever (new CCAnimate (animation)));

            // to test issue #732, uncomment the following line
            m_pSprite1.FlipX = false;
            m_pSprite1.FlipY = false;

            //
            // Animation using standard Sprite
            //
            m_pSprite2 = new CCSprite("grossini_dance_01.png");
            m_pSprite2.Position = (new CCPoint(s.Width / 2 + 80, s.Height / 2));
            AddChild(m_pSprite2);

            var moreFrames = new List<CCSpriteFrame>(20);
            for (int i = 1; i < 15; i++)
            {
                string temp;
                str = string.Format("grossini_dance_gray_{0:00}.png", i);
                CCSpriteFrame frame = cache.SpriteFrameByName(str);
                moreFrames.Add(frame);
            }

            for (int i = 1; i < 5; i++)
            {
                str = string.Format("grossini_blue_{0:00}.png", i);
                CCSpriteFrame frame = cache.SpriteFrameByName(str);
                moreFrames.Add(frame);
            }

            // append frames from another batch
            moreFrames.AddRange(animFrames);
            CCAnimation animMixed = new CCAnimation(moreFrames, 0.3f);

            m_pSprite2.RunAction(new CCRepeatForever (new CCAnimate (animMixed)));

            // to test issue #732, uncomment the following line
            m_pSprite2.FlipX = false;
            m_pSprite2.FlipY = false;

            Schedule(startIn05Secs, 0.5f);
            m_nCounter = 0;
        }
        public SpriteBatchNodeOffsetAnchorScale()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            for (int i = 0; i < 3; i++)
            {
                CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
                cache.AddSpriteFramesWithFile("animations/grossini.plist");
                cache.AddSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray");

                //
                // Animation using Sprite BatchNode
                //
                CCSprite sprite = new CCSprite("grossini_dance_01.png");
                sprite.Position = (new CCPoint(s.Width / 4 * (i + 1), s.Height / 2));

                CCSprite point = new CCSprite("Images/r1");
                point.Scale = 0.25f;
                point.Position = sprite.Position;
                AddChild(point, 200);

                switch (i)
                {
                    case 0:
                        sprite.AnchorPoint = new CCPoint(0, 0);
                        break;
                    case 1:
                        sprite.AnchorPoint = new CCPoint(0.5f, 0.5f);
                        break;
                    case 2:
                        sprite.AnchorPoint = new CCPoint(1, 1);
                        break;
                }

                point.Position = sprite.Position;

                CCSpriteBatchNode spritesheet = new CCSpriteBatchNode("animations/grossini");
                AddChild(spritesheet);

                var animFrames = new List<CCSpriteFrame>(14);
                string str = "";
                for (int k = 0; k < 14; k++)
                {
                    string temp = "";
                    if (k+1<10)
                    {
                        temp = "0" + (k + 1);
                    }
                    else
                    {
                        temp = (k + 1).ToString();
                    }
                    str = string.Format("grossini_dance_{0}.png", temp);
                    CCSpriteFrame frame = cache.SpriteFrameByName(str);
                    animFrames.Add(frame);
                }

                CCAnimation animation = new CCAnimation(animFrames, 0.3f);
                sprite.RunAction(new CCRepeatForever (new CCAnimate (animation)));

                CCActionInterval scale = new CCScaleBy(2, 2);
                CCActionInterval scale_back = (CCActionInterval)scale.Reverse();
                CCActionInterval seq_scale = (CCActionInterval)(CCSequence.FromActions(scale, scale_back));
                sprite.RunAction(new CCRepeatForever (seq_scale));

                spritesheet.AddChild(sprite, i);

                //animFrames->release();    // win32 : memory leak    2010-0415
            }
        }
Beispiel #34
0
        public bool initWithAnimation(CCAnimation pAnimation)
        {
            Debug.Assert(pAnimation != null);

            return initWithAnimation(pAnimation, true);
        }
Beispiel #35
0
 public CCAnimate(CCAnimation pAnimation)
 {
     InitWithAnimation(pAnimation);
 }
Beispiel #36
0
 public void addAnimation(CCAnimation animation, string name)
 {
     this.m_pAnimations.Add(name, animation);
 }
Beispiel #37
0
 public bool initWithAnimation(CCAnimation pAnimation)
 {
     return(this.initWithAnimation(pAnimation, true));
 }