public SpriteOffsetAnchorRotation()
        {
            sprites = new CCSprite[numOfSprites];
            pointSprites = new CCSprite[numOfSprites];

            // Create actions

            CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
            cache.AddSpriteFrames("animations/grossini.plist");
            cache.AddSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray");
            var animFrames = new List<CCSpriteFrame>();
            string tmp = "";
            for (int j = 0; j < 14; j++)
            {
                tmp = string.Format("grossini_dance_{0:00}.png", j + 1);
                CCSpriteFrame frame = cache[tmp];
                animFrames.Add(frame);
            }

            animation = new CCAnimation(animFrames, 0.3f);

            for (int i = 0; i < numOfSprites; i++)
            {
                // Animation using Sprite batch
                sprites[i] = new CCSprite("grossini_dance_01.png");
                AddChild(sprites[i], 0);

                pointSprites[i] = new CCSprite("Images/r1");
                AddChild(pointSprites[i], 1);
            }
        }
Esempio n. 2
0
        public override CCFiniteTimeAction Reverse ()
        {
            var oldArray = Animation.Frames;
            var newArray = new List<CCAnimationFrame> (oldArray.Count);

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

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

                    newArray.Add (pElement.Copy ());
                }
            }

            var newAnim = new CCAnimation (newArray, Animation.DelayPerUnit, Animation.Loops);
            newAnim.RestoreOriginalFrame = Animation.RestoreOriginalFrame;
            return new CCAnimate (newAnim);
        }
Esempio n. 3
0
        private CCAnimate (CCAnimation animation, float totalDuration) : base (totalDuration)
        {
            Debug.Assert (totalDuration == animation.Duration * animation.Loops);
            Debug.Assert (animation != null);

            Animation = animation;
            SplitTimes = new List<float> ();

            SplitTimes.Capacity = animation.Frames.Count;

            float singleDuration = Animation.Duration;
            float accumUnitsOfTime = 0;
            float newUnitOfTimeValue = singleDuration / Animation.TotalDelayUnits;

            var pFrames = Animation.Frames;

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

            foreach (var pObj in pFrames)
            {
                var frame = (CCAnimationFrame)pObj;
                float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration;
                accumUnitsOfTime += frame.DelayUnits;
                SplitTimes.Add (value);
            }
        }
Esempio n. 4
0
        public SpriteFrameTest()
        {
            CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
            cache.AddSpriteFrames("animations/grossini.plist");
            cache.AddSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray");
            cache.AddSpriteFrames("animations/grossini_blue.plist", "animations/grossini_blue");

            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[str];
                animFrames.Add(frame);
            }

            animation = new CCAnimation(animFrames, 0.3f);

            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[str];
                moreFrames.Add(frame);
            }


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

            // append frames from another batch
            moreFrames.AddRange(animFrames);

            animMixed = new CCAnimation(moreFrames, 0.3f);


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

            sprite1 = new CCSprite("grossini_dance_01.png");
            spritebatch.AddChild(sprite1);

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

            // Animation using standard Sprite
            sprite2 = new CCSprite("grossini_dance_01.png");
            AddChild(sprite2);

            // to test issue #732, uncomment the following line
            sprite2.FlipX = false;
            sprite2.FlipY = false;
        }
Esempio n. 5
0
 public void AddAnimation(CCAnimation animation, string name)
 {
     if (!animations.ContainsKey(name))
     {
         animations.Add(name, animation);
     }
 }
        public void InitializeBear()
        {
            var spriteSheet = new CCSpriteSheet("animations/AnimBear.plist");
            var walkAnimation = new CCAnimation(spriteSheet.Frames, 0.1f);
            bearAction = new CCRepeatForever(new CCAnimate(walkAnimation));

            bearSprite = new CCSprite(spriteSheet.Frames.First()) { Name = "Bear" };
        }
        public SpriteBatchNodeOffsetAnchorSkew()
        {
            CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
            cache.AddSpriteFrames("animations/grossini.plist");
            cache.AddSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray");

            // Create animations and actions

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

            animation = new CCAnimation(animFrames, 0.3f);

            // skew
            CCSkewBy skewX = new CCSkewBy (2, 45, 0);
            CCFiniteTimeAction skewX_back = (CCFiniteTimeAction)skewX.Reverse();
            CCSkewBy skewY = new CCSkewBy (2, 0, 45);
            CCFiniteTimeAction skewY_back = (CCFiniteTimeAction)skewY.Reverse();

            // scale 
            CCScaleBy scale = new CCScaleBy(2, 2);
            CCFiniteTimeAction scale_back = (CCFiniteTimeAction)scale.Reverse();

            seq_scale = new CCSequence(scale, scale_back);
            seq_skew = new CCSequence(skewX, skewX_back, skewY, skewY_back);

            sprites = new CCSprite[numOfSprites];
            pointSprites = new CCSprite[numOfSprites];

            for (int i = 0; i < numOfSprites; i++)
            {
                // Animation using Sprite batch
                sprites[i] = new CCSprite("grossini_dance_01.png");
                pointSprites[i] = new CCSprite("Images/r1");

                CCSpriteBatchNode spritebatch = new CCSpriteBatchNode("animations/grossini");
                AddChild(spritebatch);
                AddChild(pointSprites[i], 200);
                spritebatch.AddChild(sprites[i], i);
            }
        }
        public SpriteBatchNodeOffsetAnchorFlip()
        {
            CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
            cache.AddSpriteFrames("animations/grossini.plist");
            cache.AddSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray");

            // Create animations and actions

            var animFrames = new List<CCSpriteFrame>();
            string tmp = "";
            for (int j = 0; j < 14; j++)
            {
                string temp = "";
                if (j+1<10)
                {
                    temp = "0" + (j + 1);
                }
                else
                {
                    temp = (j + 1).ToString();
                }

                tmp = string.Format("grossini_dance_{0}.png", temp);
                CCSpriteFrame frame = cache[tmp];
                animFrames.Add(frame);
            }

            animation = new CCAnimation(animFrames, 0.3f);


            CCFlipY flip = new CCFlipY(true);
            CCFlipY flip_back = new CCFlipY(false);
            CCDelayTime delay = new CCDelayTime (1);

            seq = new CCSequence(delay, flip, delay, flip_back);

            sprites = new CCSprite[numOfSprites];
            pointSprites = new CCSprite[numOfSprites];

            for (int i = 0; i < numOfSprites; i++)
            {
                // Animation using Sprite batch
                sprites[i] = new CCSprite("grossini_dance_01.png");
                pointSprites[i] = new CCSprite("Images/r1");

                CCSpriteBatchNode spritebatch = new CCSpriteBatchNode("animations/grossini");
                AddChild(spritebatch);
                AddChild(pointSprites[i], 200);
                spritebatch.AddChild(sprites[i], i);
            }
        }
Esempio n. 9
0
        public Player()
        {
            CCSpriteSheet tmp = new CCSpriteSheet("poring.plist");

            //List<CCSpriteFrame> elementos = new List<CCSpriteFrame>();
            //for (int i = 1; i <= 3; i++)
            //{
            //    tmp = CCSpriteFrameCache.SharedSpriteFrameCache.SpriteFrameByName(String.Format("walk{0}.png", i));
            //    elementos.Add(tmp);
            //}
            CCAnimation anim = new CCAnimation(tmp.Frames, 0.5f);
            CCRepeatForever rep = new CCRepeatForever(new CCAnimate(anim));
            RunAction(rep);
        }
Esempio n. 10
0
        public void SetSpriteFrameWithAnimationName(string animationName, int frameIndex)
        {
            Debug.Assert(!String.IsNullOrEmpty(animationName),
                         "CCSprite#setDisplayFrameWithAnimationName. animationName must not be NULL");

            CCAnimation a = CCAnimationCache.SharedAnimationCache[animationName];

            Debug.Assert(a != null, "CCSprite#setDisplayFrameWithAnimationName: Frame not found");

            var frame = (CCAnimationFrame)a.Frames[frameIndex];

            Debug.Assert(frame != null, "CCSprite#setDisplayFrame. Invalid frame");

            SpriteFrame = frame.SpriteFrame;
        }
Esempio n. 11
0
        public override void OnEnter() {
            base.OnEnter();


            if (Parent.Tag == Tags.Client) {
                var ss = new CCSpriteSheet("MysticAnim.plist");
                var walkAnim = new CCAnimation(ss.Frames, 0.3f);
                foreach (CCSpriteFrame sf in ss.Frames) {
                    sf.Texture.IsAntialiased = false;
                }

                AddAction(new CCRepeatForever(new CCAnimate(walkAnim)));
            }

            Schedule(Update);
        }
        public SpriteOffsetAnchorSkewScale()
        {
            sprites = new CCSprite[numOfSprites];
            pointSprites = new CCSprite[numOfSprites];

            // Create actions

            CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
            cache.AddSpriteFrames("animations/grossini.plist");
            cache.AddSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray");
            var animFrames = new List<CCSpriteFrame>();
            string tmp = "";
            for (int j = 0; j < 14; j++)
            {
                tmp = string.Format("grossini_dance_{0:00}.png", j + 1);
                CCSpriteFrame frame = cache[tmp];
                animFrames.Add(frame);
            }

            animation = new CCAnimation(animFrames, 0.3f);

            // Skew
            CCSkewBy skewX = new CCSkewBy (2, 45, 0);
            CCFiniteTimeAction skewX_back = (CCFiniteTimeAction)skewX.Reverse();
            CCSkewBy skewY = new CCSkewBy (2, 0, 45);
            CCFiniteTimeAction skewY_back = (CCFiniteTimeAction)skewY.Reverse();

            seq_skew = new CCSequence(skewX, skewX_back, skewY, skewY_back);

            // Scale
            CCScaleBy scale = new CCScaleBy(2, 2);
            CCFiniteTimeAction scale_back = (CCFiniteTimeAction)scale.Reverse();

            seq_scale = new CCSequence(scale, scale_back);


            for (int i = 0; i < numOfSprites; i++)
            {
                // Animation using Sprite batch
                sprites[i] = new CCSprite("grossini_dance_01.png");
                AddChild(sprites[i], 0);

                pointSprites[i] = new CCSprite("Images/r1");
                AddChild(pointSprites[i], 1);
            }
        }
Esempio n. 13
0
        public SpriteOffsetAnchorScale()
        {
            CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
            cache.AddSpriteFrames("animations/grossini.plist");
            cache.AddSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray");

            sprites = new CCSprite[numOfSprites];
            pointSprites = new CCSprite[numOfSprites];

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

            animation = new CCAnimation(animFrames, 0.3f);

            for (int i = 0; i < numOfSprites; i++)
            {
                // Animation using Sprite BatchNode
                sprites[i] = new CCSprite("grossini_dance_01.png");
                AddChild(sprites[i], 0);

                pointSprites[i] = new CCSprite("Images/r1");
                AddChild(pointSprites[i], 1);


                CCFiniteTimeAction scale = new CCScaleBy(2, 2);
                CCFiniteTimeAction scale_back = (CCFiniteTimeAction)scale.Reverse();
                seq_scale = (CCFiniteTimeAction)(new CCSequence(scale, scale_back));
            }
        }
Esempio n. 14
0
        public SpriteBatchNodeChildren()
        {
            CCSpriteBatchNode batch = new CCSpriteBatchNode("animations/grossini", 50);
            AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

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

            sprite1 = new CCSprite("grossini_dance_01.png");
            sprite2 = new CCSprite("grossini_dance_02.png");
            sprite3 = new CCSprite("grossini_dance_03.png");

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

            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[str];
                animFrames.Add(frame);
            }

            animation = new CCAnimation(animFrames, 0.2f);

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

            seq2 = (CCFiniteTimeAction)action_rot.Reverse();
        }
Esempio n. 15
0
        public SpriteFrameAliasNameTest()
        {
            CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
            cache.AddSpriteFrames("animations/grossini-aliases.plist", "animations/grossini-aliases");

            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[str];
                animFrames.Add(frame);
            }

            animation = new CCAnimation(animFrames, 0.3f);

            sprite = new CCSprite("grossini_dance_01.png");

            CCSpriteBatchNode spriteBatch = new CCSpriteBatchNode("animations/grossini-aliases");
            spriteBatch.AddChild(sprite);
            AddChild(spriteBatch);
        }
Esempio n. 16
0
        public SpriteAnimationSplit()
        {
            var texture = CCTextureCache.SharedTextureCache.AddImage("animations/dragon_animation");
            CCSize contentSizeInPixels = texture.ContentSizeInPixels;
            float height = contentSizeInPixels.Height / 4.0f;
            float heightOffset = height / 2.0f;
            float width = contentSizeInPixels.Width / 5.0f;

            // Manually add frames to the frame cache
            // The rects in pixels of each frame are determined from the textureatlas 
            var frame0 = new CCSpriteFrame(texture, new CCRect(width * 0, heightOffset + height * 0, width, height));
            var frame1 = new CCSpriteFrame(texture, new CCRect(width * 1, heightOffset + height * 0, width, height));
            var frame2 = new CCSpriteFrame(texture, new CCRect(width * 2, heightOffset + height * 0, width, height));
            var frame3 = new CCSpriteFrame(texture, new CCRect(width * 3, heightOffset + height * 0, width, height));

            // Note: The height positioning below is a bit of voodoo because the sprite atlas isn't currently packed tightly
            // See the dragon_animation.png file
            var frame4 = new CCSpriteFrame(texture, new CCRect(width * 0, heightOffset * 1.6f + height * 1, width, height));
            var frame5 = new CCSpriteFrame(texture, new CCRect(width * 1, heightOffset * 1.6f + height * 1, width, height));

            // Animation using Sprite BatchNode
            sprite = new CCSprite(frame0);
            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);
            seq = new CCSequence(animate, new CCFlipX(true), animate, new CCFlipX(false));
        }
 public static CCAction GetActionRepeteatForever(List<CCSpriteFrame> frames, float delay = 0.2f)
 {
     //List<CCSpriteFrame> walkAnimFrames = SpriteAnimationHelper.GetFromCacheFrameFromNumToNum("{0}.png", 0, 5);
     var framesAnim = new CCAnimation(frames, delay);
     return new CCRepeatForever(new CCAnimate(framesAnim));
 }
Esempio n. 18
0
        void AddMonkey()
        {
            var spriteSheet = new CCSpriteSheet ("animations/monkey.plist");
            var animationFrames = spriteSheet.Frames.FindAll ((x) => x.TextureFilename.StartsWith ("frame"));

            walkAnim = new CCAnimation (animationFrames, 0.1f);
            walkRepeat = new CCRepeatForever (new CCAnimate (walkAnim));
            monkey = new CCSprite (animationFrames.First ()) { Name = "Monkey" };
            monkey.Scale = 0.25f;

            AddChild (monkey);
        }
Esempio n. 19
0
        //IntroLayer Scene;
        public Hero()
        {
            //Scene = scene;

            head = new CCSprite(CCApplication.SharedApplication.SpriteFrameCache["Image 577 at frame 10.png"]);
            head.Scale = 0.75f;
            head.SetPosition(0, 7);

            leg = new CCSprite(CCApplication.SharedApplication.SpriteFrameCache["Image 523 at frame 10.png"]);
            leg.Scale = 0.75f;
            leg.SetPosition(12, -23);

            AddChild(leg);
            AddChild(head);

            // CABEZA ESTATICO ============================================================================================

            sqIdelAnimation1 = new CCAnimation(new List<CCSpriteFrame>() {
                CCApplication.SharedApplication.SpriteFrameCache["Image 544 at frame 10.png"],
                CCApplication.SharedApplication.SpriteFrameCache["Image 545 at frame 10.png"],
                CCApplication.SharedApplication.SpriteFrameCache["Image 546 at frame 10.png"]
            }, 0.2f);
            sqIdelAction1 = new CCRepeatForever(new CCAnimate(sqIdelAnimation1));

            //head.RunAction(sqIdelAction1);

            //DISPARANDO ============================================================================================

            sqIdelAnimationFireSmall = new CCAnimation(new List<CCSpriteFrame>() {
                CCApplication.SharedApplication.SpriteFrameCache["Image 635 at frame 10.png"],
                CCApplication.SharedApplication.SpriteFrameCache["Image 637 at frame 10.png"],
                CCApplication.SharedApplication.SpriteFrameCache["Image 638 at frame 10.png"],
                CCApplication.SharedApplication.SpriteFrameCache["Image 544 at frame 10.png"]
            }, 0.15f);
            sqIdelActionFireSmall = new CCRepeatForever(new CCAnimate(sqIdelAnimationFireSmall));

            //PIERNAS ESTATICO

            // PIERNAS ANDANDO ============================================================================================
            sqIdelActionStopped = new CCRepeatForever(new CCAnimate(new CCAnimation(new List<CCSpriteFrame>() {
                CCApplication.SharedApplication.SpriteFrameCache["Image 523 at frame 10.png"] },
                0.15f)));

            sqIdelAnimation2 = new CCAnimation(new List<CCSpriteFrame>() {
                CCApplication.SharedApplication.SpriteFrameCache["Image 524 at frame 10.png"],
                CCApplication.SharedApplication.SpriteFrameCache["Image 525 at frame 10.png"],
                CCApplication.SharedApplication.SpriteFrameCache["Image 526 at frame 10.png"],
                CCApplication.SharedApplication.SpriteFrameCache["Image 527 at frame 10.png"]
            }, 0.15f);
            sqIdelActionRun = new CCRepeatForever(new CCAnimate(sqIdelAnimation2));

            //leg.RunAction(sqIdelActionRun);
            //SALTO ============================================================================================

            sqIdelAnimation3 = new CCAnimation(new List<CCSpriteFrame>() {
                  CCApplication.SharedApplication.SpriteFrameCache["Image 539 at frame 10.png"],
                  CCApplication.SharedApplication.SpriteFrameCache["Image 540 at frame 10.png"],
                  CCApplication.SharedApplication.SpriteFrameCache["Image 541 at frame 10.png"],
                  CCApplication.SharedApplication.SpriteFrameCache["Image 542 at frame 10.png"],
                  CCApplication.SharedApplication.SpriteFrameCache["Image 543 at frame 10.png"],
                  CCApplication.SharedApplication.SpriteFrameCache["Image 544 at frame 10.png"]
              }, 0.1f);
            sqIdelAction3 = new CCRepeatForever(new CCAnimate(sqIdelAnimation3));

            //leg.RunAction(sqI

            //AGACHADO ==========================================================================
            sqIdelAnimation4 = new CCAnimation(new List<CCSpriteFrame>() {
               CCApplication.SharedApplication.SpriteFrameCache["Image 533 at frame 10.png"],
               CCApplication.SharedApplication.SpriteFrameCache["Image 534 at frame 10.png"],
               CCApplication.SharedApplication.SpriteFrameCache["Image 535 at frame 10.png"],
               CCApplication.SharedApplication.SpriteFrameCache["Image 536 at frame 10.png"],
               CCApplication.SharedApplication.SpriteFrameCache["Image 537 at frame 10.png"],
               CCApplication.SharedApplication.SpriteFrameCache["Image 538 at frame 10.png"],
               CCApplication.SharedApplication.SpriteFrameCache["Image 544 at frame 10.png"]
               }, 0.2f);

            sqIdelActionSit = new CCRepeatForever(new CCAnimate(sqIdelAnimation4));

            head.RunAction(sqIdelAction1);

            leg.RunAction(sqIdelActionStopped);

            Schedule();
        }
Esempio n. 20
0
 public CCAnimate(CCAnimation animation) : this(animation, animation.Duration *animation.Loops)
 {
 }
Esempio n. 21
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);
            }
        }
        public CCAnimate CreateAnimateAction(CCDirector director)
        {
            var frameList = new List<CCSpriteFrame>();

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

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

            return animate;
        }
Esempio n. 23
0
        public ActionAnimate()
        {
            var animation = new CCAnimation();
            for (var i = 1; i < 15; i++)
            {
                var szName = String.Format("Images/grossini_dance_{0:00}", i);
                animation.AddSpriteFrame(szName);
            }

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

            action = new CCAnimate(animation);

            var cache = CCAnimationCache.SharedAnimationCache;
            cache.AddAnimations("animations/animations-2.plist");
            var animation2 = cache["dance_1"];

            action2 = new CCAnimate (animation2);

            var animation3 = animation2.Copy();
            animation3.Loops = 4;

            action3 = new CCAnimate (animation3);
        }
Esempio n. 24
0
        public void InitializeMonkey()
        {
            var spriteSheet = new CCSpriteSheet("animations/monkey.plist");
            var walkAnimation = new CCAnimation(spriteSheet.Frames, 0.1f);
            monkeyAction = new CCRepeatForever(new CCAnimate(walkAnimation));

            // Load the frames using the Frames property which
            var animationFrames = spriteSheet.Frames.FindAll((x) =>
                {
                    return x.TextureFilename.StartsWith("frame");
                });

            monkeySprite = new CCSprite(animationFrames.First()) { Name = "Monkey" };
            monkeySprite.Scale = 0.5f;
        }
Esempio n. 25
0
 public CCAnimate (CCAnimation animation) : this (animation, animation.Duration * animation.Loops)
 {
 }
Esempio n. 26
0
		private void createActions()
		{
			//swing action for health drops
			CCFiniteTimeAction easeSwing = new CCSequence(
						   new CCEaseInOut(new CCRotateTo(1.2f, -10), 2),
						   new CCEaseInOut(new CCRotateTo(1.2f, 10), 2));
			_swingHealth = new CCRepeatForever(easeSwing);
			//_swingHealth ->retain();

			//action sequence for shockwave: fade out, call back when done
			_shockwaveSequence = new CCSequence(
							new CCFadeOut(1.0f),
							new CCCallFunc(shockwaveDone));
			//_shockwaveSequence->retain();

			//action to grow bomb
			_growBomb = new CCScaleTo(6.0f, 1);
			//_growBomb->retain();

			//action to rotate sprites
			_rotateSprite = new CCRepeatForever(new CCRotateBy(0.5f, -90));
			//_rotateSprite->retain();


			//sprite animations
			CCAnimation animation;

			var spriteFrameCache = CCSpriteFrameCache.SharedSpriteFrameCache;

			animation = new CCAnimation();
			CCSpriteFrame frame;
			int i;
			//animation for ground hit
			for (i = 1; i <= 10; i++)
			{

				frame = spriteFrameCache[String.Format("boom{0}.png", i)];
				animation.AddSpriteFrame(frame);

			}



			animation.DelayPerUnit = (1 / 10.0f);
			animation.RestoreOriginalFrame = true;
			_groundHit = new CCSequence(
						new CCMoveBy(0, new CCPoint(0, _screenSize.Height * 0.12f)),
						new CCAnimate(animation),
						new CCCallFuncN(animationDone));
			//_groundHit->retain();

			animation = new CCAnimation();
			//animation for falling object explosion
			for (i = 1; i <= 7; i++)
			{

				frame = spriteFrameCache[String.Format("explosion_small{0}.png", i)];

				animation.AddSpriteFrame(frame);
			}

			animation.DelayPerUnit = 0.5f / 7.0f;
			animation.RestoreOriginalFrame = true;
			_explosion = new CCSequence(
					new CCAnimate(animation),
					new CCCallFuncN(animationDone)
					);
			;
			// _explosion->retain();
		}
Esempio n. 27
0
 // Perform deep copy of CCAnimation
 protected CCAnimation(CCAnimation animation) : this(animation.Frames, animation.DelayPerUnit, animation.Loops)
 {
     RestoreOriginalFrame = animation.RestoreOriginalFrame;
 }
Esempio n. 28
0
 // Perform deep copy of CCAnimation
 protected CCAnimation(CCAnimation animation) : this(animation.Frames, animation.DelayPerUnit, animation.Loops)
 {
     RestoreOriginalFrame = animation.RestoreOriginalFrame;
 }
Esempio n. 29
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);
            }
        }
        void AddMonkey()
        {
            var spriteSheet = new CCSpriteSheet ("animations/monkey.plist");
            var animationFrames = spriteSheet.Frames.FindAll ((x) => x.TextureFilename.StartsWith ("frame"));

            walkAnim = new CCAnimation (animationFrames, 0.1f);
            walkRepeat = new CCRepeatForever (new CCAnimate (walkAnim));
            monkey = new CCSprite (animationFrames.First ()) { Name = "Monkey" };

            var baselineScale = 0.25f; //monkey image actual size is 4x what looks good at baseline, so scale by 0.25 for baseline
            var contentScale = contentScaleFactorX > contentScaleFactorY ? contentScaleFactorX : contentScaleFactorY; //use the larger scale if they are not equal

            monkey.Scale = baselineScale * contentScale;

            AddChild (monkey);
        }
Esempio n. 31
0
        public AnimationCache()
        {
            var frameCache = CCSpriteFrameCache.SharedSpriteFrameCache;
            frameCache.AddSpriteFrames("animations/grossini.plist");
            frameCache.AddSpriteFrames("animations/grossini_gray.plist");
            frameCache.AddSpriteFrames("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[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[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[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["dance"];
            normal.RestoreOriginalFrame = true;
            CCAnimation dance_grey = animCache["dance_gray"];
            dance_grey.RestoreOriginalFrame = true;
            CCAnimation dance_blue = animCache["dance_blue"];
            dance_blue.RestoreOriginalFrame = true;

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

            seqAnimation = new CCSequence(animN, animG, animB);

            grossini = new CCSprite();
            AddChild(grossini);
        }
Esempio n. 32
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);
 }