public void AddAnimation(CCAnimation animation, string name)
 {
     if (!m_pAnimations.ContainsKey(name))
     {
         m_pAnimations.Add(name, animation);
     }
 }
Exemple #2
0
        public ActorBase(ActorData data)
        {
            ActorData = data;
            //创建攻击动画
            List <CCSpriteFrame> _attackFrames      = new List <CCSpriteFrame>();
            List <CCSpriteFrame> _attackFrames_flip = new List <CCSpriteFrame>();

            for (int i = 0; i < 4; i++)
            {
                _attackFrames.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(data.ActorID + "_" + i + ".png"));
                _attackFrames_flip.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(data.ActorID + "f_" + i + ".png"));
            }
            _action_attack      = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_attackFrames, 0.1f));
            _action_attack_flip = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_attackFrames_flip, 0.1f));
            //创建行走动画
            List <CCSpriteFrame> _runFrames      = new List <CCSpriteFrame>();
            List <CCSpriteFrame> _runFrames_flip = new List <CCSpriteFrame>();

            for (int i = 4; i < 6; i++)
            {
                _runFrames.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(data.ActorID + "_" + i + ".png"));
                _runFrames_flip.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(data.ActorID + "f_" + i + ".png"));
            }
            _action_run      = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_runFrames, 0.1f));
            _action_run_flip = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_runFrames_flip, 0.1f));
            //创建站立动画
            List <CCSpriteFrame> _standFrames      = new List <CCSpriteFrame>();
            List <CCSpriteFrame> _standFrames_flip = new List <CCSpriteFrame>();

            for (int i = 6; i < 7; i++)
            {
                _standFrames.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(data.ActorID + "_" + i + ".png"));
                _standFrames_flip.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(data.ActorID + "f_" + i + ".png"));
            }
            _action_stand      = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_standFrames, 0.2f));
            _action_stand_flip = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_standFrames_flip, 0.2f));
            //创建死亡动画
            List <CCSpriteFrame> _deadFrames      = new List <CCSpriteFrame>();
            List <CCSpriteFrame> _deadFrames_flip = new List <CCSpriteFrame>();

            for (int i = 7; i < 9; i++)
            {
                _deadFrames.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(data.ActorID + "_" + i + ".png"));
                _deadFrames_flip.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(data.ActorID + "f_" + i + ".png"));
            }
            _action_dead      = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_deadFrames, 0.3f));
            _action_dead_flip = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_deadFrames_flip, 0.3f));
            //初始化默认帧
            base.initWithSpriteFrame(_standFrames[0]);
        }
Exemple #3
0
        private void LoadPicture()
        {
            CCTexture2D          speakerpic = Media.PictureManager.GetCCTexture2DWithFile(PictuerName);
            List <CCSpriteFrame> frames     = new List <CCSpriteFrame>();

            for (int i = 0; i < FrameNumber; i++)
            {
                CCSpriteFrame frame = CCSpriteFrame.frameWithTexture(speakerpic, new CCRect(i * PictuerWidth, 0, PictuerWidth, PictuerHeight));
                frames.Add(frame);
            }
            CCAnimation ani = CCAnimation.animationWithFrames(frames);

            this.initWithSpriteFrame(frames[0]);
            action = CCAnimate.actionWithDuration(1f, ani, true);
        }
        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);
        }
        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);
            }
        }
        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);
        }
Exemple #7
0
        public Truck()
        {
            //[self setTextureRect:CGRectMake(0, 0, 308, 185)];
            caster1 = new CCSprite(CCApplication.SharedApplication.SpriteFrameCache["Image 906 at frame 10.png"]);
            caster1.Position = new CCPoint(50, -38);
            caster2 = new CCSprite(CCApplication.SharedApplication.SpriteFrameCache["Image 906 at frame 10.png"]);
            caster2.Position = new CCPoint(-63, -38);

            CCSpriteFrame fc1 = CCApplication.SharedApplication.SpriteFrameCache["Image 904 at frame 10.png"];
            CCSpriteFrame fc2 = CCApplication.SharedApplication.SpriteFrameCache["Image 904 at frame 10.png"];
            CCSpriteFrame fc3 = CCApplication.SharedApplication.SpriteFrameCache["Image 904 at frame 10.png"];

            var curtainanimation = new CCAnimation(new List<CCSpriteFrame>() { fc1, fc2, fc3 }, 0.2f);

            var curtainaction1 = new CCRepeatForever(new CCAnimate(curtainanimation));
            var curtainaction2 = new CCRepeatForever(new CCAnimate(curtainanimation));
            var curtainaction3 = new CCRepeatForever(new CCAnimate(curtainanimation));

            curtain1 = new CCSprite(fc1);
            curtain2 = new CCSprite(fc1);
            curtain3 = new CCSprite(fc1);
            curtain1.Position = new CCPoint(-10, -5);
            curtain2.Position = new CCPoint(-40, -5);
            curtain3.Position = new CCPoint(-70, -5);

            head = new CCSprite(CCApplication.SharedApplication.SpriteFrameCache["Image 907 at frame 10.png"]);
            body = new CCSprite(CCApplication.SharedApplication.SpriteFrameCache["Image 915 at frame 10.png"]);
            body.Position = new CCPoint(-8, 5);
            door = new CCSprite(CCApplication.SharedApplication.SpriteFrameCache["Image 908 at frame 10.png"]);
            door.Position = new CCPoint(50, -5);
            light = new CCSprite(CCApplication.SharedApplication.SpriteFrameCache["Image 909 at frame 10.png"]);
            light.Position = new CCPoint(165, -30);

            AddChild(caster1);
            AddChild(caster2);
            AddChild(head);
            AddChild(curtain1);
            RunAction(curtainaction1);
            AddChild(curtain2);
            RunAction(curtainaction2);
            AddChild(curtain3);
            RunAction(curtainaction3);

            AddChild(body);
            AddChild(door);
            AddChild(light);
        }
Exemple #8
0
        public SpriteOffsetAnchorFlip()
        {
            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++)
            {
                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);

            var flip      = new CCFlipY(true);
            var flip_back = flip.Reverse();
            var 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");
                AddChild(sprites[i], 0);

                pointSprites[i] = new CCSprite("Images/r1");
                AddChild(pointSprites[i], 1);
            }
        }
Exemple #9
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));
            }
        }
Exemple #10
0
        public SpriteBatchNodeOffsetAnchorRotation()
        {
            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);

            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);
            }
        }
Exemple #11
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();
        }
Exemple #12
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;
        }
        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);
        }
        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)(new CCSequence(animate,
                                                                           new CCFlipX(true),
                                                                           (CCFiniteTimeAction)animate.Copy(),
                                                                           new CCFlipX(false)
                                                                           ));

            sprite.RunAction(new CCRepeatForever(seq));
            //animFrames->release();    // win32 : memory leak    2010-0415
        }
        public SpriteAnimationSplit()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            CCTexture2D texture = CCTextureCache.sharedTextureCache().addImage("animations/images/dragon_animation");

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

            //
            // Animation using Sprite BatchNode
            //
            CCSprite sprite = CCSprite.spriteWithSpriteFrame(frame0);

            sprite.position = (new CCPoint(s.width / 2 - 80, s.height / 2));
            addChild(sprite);

            List <CCSpriteFrame> 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 = CCAnimation.animationWithFrames(animFrames, 0.2f);
            CCAnimate        animate   = CCAnimate.actionWithAnimation(animation, false);
            CCActionInterval seq       = (CCActionInterval)(CCSequence.actions(animate,
                                                                               CCFlipX.actionWithFlipX(true),
                                                                               (CCFiniteTimeAction)animate.copy(),
                                                                               CCFlipX.actionWithFlipX(false)
                                                                               ));

            sprite.runAction(CCRepeatForever.actionWithAction(seq));
            //animFrames->release();    // win32 : memory leak    2010-0415
        }
Exemple #16
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);

            Schedule(t => {
                //visibleBananas.Add (AddBanana ());
                UpdateMonkeyMovements(t);
            });
        }
Exemple #17
0
        void CreatePlayer()
        {
            player.Name     = "player";
            player.Position = new CCPoint(VisibleBoundsWorldspace.MinX + player.ContentSize.Width * 1.5f, ContentSize.Height * 0.75f);
            AddChild(player);
            this.ReorderChild(player, 10);

            CCAnimation playerAnimation = new CCAnimation();

            for (int i = 1; i <= 3; i++)
            {
                playerAnimation.AddSpriteFrame(new CCSprite(string.Format("player-{0}", i)));
            }
            playerAnimation.AddSpriteFrame(playerAnimation.Frames[1].SpriteFrame);
            playerAnimation.DelayPerUnit = 0.01f;

            var animate         = new CCAnimate(playerAnimation);
            var animationAction = new CCRepeatForever(animate);

            player.RunAction(animationAction);
        }
Exemple #18
0
        private void CreateSprite()
        {
            var spriteSheet     = new CCSpriteSheet("mike11.plist");
            var animationFrames = spriteSheet.Frames;

            var walkAnim = new CCAnimation(animationFrames, 0.15f);

            walkRepeat  = new CCRepeatForever(new CCAnimate(walkAnim));
            bikerSprite = new CCSprite(animationFrames.First())
            {
                Name = "Mike11"
            };
            bikerSprite.AnchorPoint = CCPoint.AnchorMiddleBottom;
            AddChild(bikerSprite);

            forceSprite           = new CCSprite("force_0");
            forceSprite.PositionX = 56;
            forceSprite.PositionY = 16;
            forceSprite.Opacity   = 0;
            AddChild(forceSprite);
        }
Exemple #19
0
        public Uncle_sprite()
        {
            //uncledata = data;

            // 创建走的动画
            List <CCSpriteFrame> _runFream = new List <CCSpriteFrame>();

            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile(@"plist/zhengyu");
            CCSpriteBatchNode sheet = CCSpriteBatchNode.batchNodeWithFile(@"plist/Images/zhengyu");

            this.addChild(sheet);
            for (int i = 1; i <= 4; i++)
            {
                _runFream.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(String.Format("MM0{0}.png", i)));
            }
            _run = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_runFream, 0.12f));

            List <CCSpriteFrame> _actackFream = new List <CCSpriteFrame>();

            // 创建攻击时候动作
            for (int i = 1; i <= 5; i++)
            {
                _actackFream.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(String.Format("Mthrow0{0}.png", i)));
            }
            _actack = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_actackFream, 0.3f));

            position = new CCPoint(100, 100);
            // 初始化开始帧
            base.initWithSpriteFrame(_runFream[0]);


            // 如果手机倾斜
            if (Accelerometer.IsSupported)
            {
                gSensor = new Accelerometer();
                gSensor.CurrentValueChanged += new EventHandler <SensorReadingEventArgs <AccelerometerReading> >(gSensor_CurrentValueChanged);
                gSensor.Start();
            }
        }
        public static void Init()
        {
            // EXPLOSIONS

            // rocket explosion animation
            rocketExplosionSpriteSheet     = new CCSpriteSheet("animations/rocket_explosion.plist", "animations/rocket_explosion.xnb");
            rocketExplosionAnimationFrames = rocketExplosionSpriteSheet.Frames.FindAll(x => x.TextureFilename.StartsWith("frame"));
            CCAnimation rocketExplosionAnimation = new CCAnimation(rocketExplosionAnimationFrames, 0.1f);

            rocketExplosionAction = new CCRepeat(new CCAnimate(rocketExplosionAnimation), 1);

            // explosion_1 animation
            explosion1SpriteSheet     = new CCSpriteSheet("animations/explosion_1.plist", "animations/explosion_1.xnb");
            explosion1AnimationFrames = explosion1SpriteSheet.Frames.FindAll(x => x.TextureFilename.StartsWith("frame"));
            CCAnimation explosion1Animation = new CCAnimation(explosion1AnimationFrames, 0.1f);

            explosion1Action = new CCRepeat(new CCAnimate(explosion1Animation), 1);

            // explosion_2 animation
            explosion2SpriteSheet     = new CCSpriteSheet("animations/explosion_2.plist", "animations/explosion_2.xnb");
            explosion2AnimationFrames = explosion2SpriteSheet.Frames.FindAll(x => x.TextureFilename.StartsWith("frame"));
            CCAnimation explosion2Animation = new CCAnimation(explosion2AnimationFrames, 0.1f);

            explosion2Action = new CCRepeat(new CCAnimate(explosion2Animation), 1);

            // explosion_3 animation
            explosion3SpriteSheet     = new CCSpriteSheet("animations/explosion_3.plist", "animations/explosion_3.xnb");
            explosion3AnimationFrames = explosion3SpriteSheet.Frames.FindAll(x => x.TextureFilename.StartsWith("frame"));
            CCAnimation explosion3Animation = new CCAnimation(explosion3AnimationFrames, 0.12f);

            explosion3Action = new CCRepeat(new CCAnimate(explosion3Animation), 1);

            // Alien bomb
            alienBombSpriteSheet     = new CCSpriteSheet("animations/bomb_gimped.plist", "animations/bomb_gimped.xnb");
            alienBombAnimationFrames = alienBombSpriteSheet.Frames.FindAll(x => x.TextureFilename.StartsWith("frame"));
            alienBombAnimation       = new CCAnimation(alienBombAnimationFrames, 0.08f);
            alienBombAction          = new CCRepeatForever(new CCAnimate(alienBombAnimation));
            // alienBombAction = new CCAnimate(alienBombAnimation);
        }
Exemple #21
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));
        }
		/** initializes the action with an Animation and will restore the original frame when the animation is over */
		public void initWithAnimation(CCAnimation anim){
			NSUtils.Assert( anim!=null, "Animate: argument Animation must be non-nil");
			
			float singleDuration = anim.duration;
			base.initWithDuration (singleDuration * anim.loops);
			_nextFrame = 0;
			this.animation = anim;
			_origFrame = null;
			_executedLoops = 0;

			_splitTimes = new List<float> (anim.frames.Count);
			float accumUnitsOfTime = 0;
			float newUnitOfTimeValue = singleDuration / anim.totalDelayUnits;

			
			var enumerator = anim.frames.GetEnumerator();
			while (enumerator.MoveNext()) {
				var frame = enumerator.Current;
				float value =  (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration;
				accumUnitsOfTime += frame.delayUnits;
				
				_splitTimes.Add(value);
			}	
		}
Exemple #23
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)(new CCSequence(scale, scale_back));
                sprite.RunAction(new CCRepeatForever(seq_scale));

                spritesheet.AddChild(sprite, i);

                //animFrames->release();    // win32 : memory leak    2010-0415
            }
        }
		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;
		}
		/** creates the action with an Animation and will restore the original frame when the animation is over */
		public CCAnimate(CCAnimation animation){
			initWithAnimation (animation);		
		}
        public SpriteFrameTest()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            // 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");
            cache.addSpriteFramesWithFile("animations/grossini_gray", "animations/images/grossini_gray");
            cache.addSpriteFramesWithFile("animations/grossini_blue", "animations/images/grossini_blue");

            //
            // Animation using Sprite BatchNode
            //
            m_pSprite1          = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
            m_pSprite1.position = (new CCPoint(s.width / 2 - 80, s.height / 2));

            CCSpriteBatchNode spritebatch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini");

            spritebatch.addChild(m_pSprite1);
            addChild(spritebatch);

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

            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 = cache.spriteFrameByName(str);
                animFrames.Add(frame);
            }

            CCAnimation animation = CCAnimation.animationWithFrames(animFrames);

            m_pSprite1.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithAnimation(animation, false)));

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

            //
            // Animation using standard Sprite
            //
            m_pSprite2          = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
            m_pSprite2.position = (new CCPoint(s.width / 2 + 80, s.height / 2));
            addChild(m_pSprite2);


            List <CCSpriteFrame> moreFrames = new List <CCSpriteFrame>(20);

            for (int i = 1; i < 15; i++)
            {
                string temp;
                if (i < 10)
                {
                    temp = "0" + i;
                }
                else
                {
                    temp = i.ToString();
                }
                str = string.Format("grossini_dance_gray_{0}.png", temp);
                CCSpriteFrame frame = cache.spriteFrameByName(str);
                moreFrames.Add(frame);
            }


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

            // append frames from another batch
            moreFrames.AddRange(animFrames);
            CCAnimation animMixed = CCAnimation.animationWithFrames(moreFrames);


            m_pSprite2.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithAnimation(animMixed, false)));



            // to test issue #732, uncomment the following line
            m_pSprite2.IsFlipX = (false);
            m_pSprite2.IsFlipY = (false);

            schedule(startIn05Secs, 0.5f);
            m_nCounter = 0;
        }
Exemple #27
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);
        }
        public SpriteBatchNodeOffsetAnchorSkew()
        {
            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 (j + 1 < 10)
                    {
                        temp = "0" + (j + 1);
                    }
                    else
                    {
                        temp = (j + 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;

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

                CCFiniteTimeAction seq_skew = CCSequence.FromActions(skewX, skewX_back, skewY, skewY_back);
                sprite.RunAction(new CCRepeatForever((CCActionInterval)seq_skew));

                spritebatch.AddChild(sprite, i);
            }
        }
        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);
        }
        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(array, delayPerUnit, (uint) loops);

                animation.RestoreOriginalFrame = restoreOriginalFrame;

                SharedAnimationCache.AddAnimation(animation, name);
            }
        }
Exemple #31
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);


            CCSprite spritebatch = new CCSprite("animations/grossini");

            sprite1 = new CCSprite("grossini_dance_01.png");
            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;
        }
Exemple #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;
        }
		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);
			}
		}
        public SpriteBatchNodeOffsetAnchorRotation()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            for (int i = 0; i < 3; i++)
            {
                CCSpriteFrameCache cache = CCSpriteFrameCache.sharedSpriteFrameCache();
                cache.addSpriteFramesWithFile("animations/grossini");
                cache.addSpriteFramesWithFile("animations/grossini_gray", "animations/images/grossini_gray");

                //
                // Animation using Sprite BatchNode
                //
                CCSprite sprite = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
                sprite.position = (new CCPoint(s.width / 4 * (i + 1), s.height / 2));

                CCSprite point = CCSprite.spriteWithFile("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 = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini");
                addChild(spritebatch);

                List <CCSpriteFrame> 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 + "";
                    }
                    str = string.Format("grossini_dance_{0}.png", temp);
                    CCSpriteFrame frame = cache.spriteFrameByName(str);
                    animFrames.Add(frame);
                }

                CCAnimation animation = CCAnimation.animationWithFrames(animFrames);
                sprite.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithAnimation(animation, false)));
                sprite.runAction(CCRepeatForever.actionWithAction(CCRotateBy.actionWithDuration(10, 360)));

                spritebatch.addChild(sprite, i);

                //animFrames.release();    // win32 : memory leak    2010-0415
            }
        }
Exemple #35
0
        public SpriteOffsetAnchorSkewScale()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            for (int i = 0; i < 3; i++)
            {
                CCSpriteFrameCache cache = CCSpriteFrameCache.sharedSpriteFrameCache();
                cache.addSpriteFramesWithFile("animations/grossini");
                cache.addSpriteFramesWithFile("animations/grossini_gray", "animations/images/grossini_gray");

                //
                // Animation using Sprite batch
                //
                CCSprite sprite = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
                sprite.position = (new CCPoint(s.width / 4 * (i + 1), s.height / 2));

                CCSprite point = CCSprite.spriteWithFile("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;

                List <CCSpriteFrame> 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.spriteFrameByName(tmp);
                    animFrames.Add(frame);
                }

                CCAnimation animation = CCAnimation.animationWithFrames(animFrames);
                sprite.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithDuration(2.8f, animation, false)));

                animFrames = null;

                // Skew
                CCSkewBy         skewX      = CCSkewBy.actionWithDuration(2, 45, 0);
                CCActionInterval skewX_back = (CCActionInterval)skewX.reverse();
                CCSkewBy         skewY      = CCSkewBy.actionWithDuration(2, 0, 45);
                CCActionInterval skewY_back = (CCActionInterval)skewY.reverse();

                CCFiniteTimeAction seq_skew = CCSequence.actions(skewX, skewX_back, skewY, skewY_back);
                sprite.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq_skew));

                // Scale
                CCScaleBy          scale      = CCScaleBy.actionWithDuration(2, 2);
                CCActionInterval   scale_back = (CCActionInterval)scale.reverse();
                CCFiniteTimeAction seq_scale  = CCSequence.actions(scale, scale_back);
                sprite.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq_scale));

                addChild(sprite, 0);
            }
        }
Exemple #36
0
        void CreatePipesAndCoins()
        {
            var pipeNode = new CCNode();

            pipeNode.AnchorPoint = CCPoint.Zero;
            pipeNode.Name        = "pipe";

            var bottomPipe = new CCSprite("pipe");

            bottomPipe.AnchorPoint = CCPoint.Zero;
            bottomPipe.ScaleX      = 0.5f;
            bottomPipe.FlipY       = true;
            bottomPipe.Name        = "bottomPipe";
            bottomPipe.Position    = new CCPoint(0, 0);

            var pipeGap = new CCDrawNode();

            pipeGap.AnchorPoint = CCPoint.Zero;
            pipeGap.DrawRect(new CCRect(0, 0, 1, (player.ContentSize.Height * 2.8f) - pipeGapShrink), CCColor4B.Red);
            pipeGap.Name     = "sensorScore";
            pipeGap.Position = new CCPoint(bottomPipe.ScaledContentSize.Width, bottomPipe.ContentSize.Height);
            pipeGap.Visible  = false;

            var topPipe = new CCSprite("pipe");

            topPipe.AnchorPoint = CCPoint.Zero;
            topPipe.ScaleX      = 0.5f;
            topPipe.Name        = "topPipe";
            topPipe.Position    = new CCPoint(0, bottomPipe.ContentSize.Height + pipeGap.ContentSize.Height);

            pipeNode.AddChild(bottomPipe);
            pipeNode.AddChild(pipeGap);
            pipeNode.AddChild(topPipe);


            AddChild(pipeNode);
            this.ReorderChild(pipeNode, -20);

            float xPosition = ContentSize.Width;
            float yPosition = CCRandom.Next(-530, 5);

            pipeNode.Position = new CCPoint(xPosition, yPosition);

            //Create coin
            var coin = new CCSprite("gold_1");

            coin.Name  = "coin";
            coin.Scale = 0.75f;

            int coinPos = CCRandom.Next(0, 3);

            if (coinPos == 0)
            {
                coin.Tag       = 0;
                coin.PositionX = topPipe.PositionX + 190;
                coin.PositionY = topPipe.PositionY + 120;
            }
            else if (coinPos == 1)
            {
                coin.Tag       = 1;
                coin.PositionX = topPipe.PositionX + coin.ContentSize.Width / 3;
                coin.PositionY = topPipe.PositionY - pipeGap.ContentSize.Height / 2;
            }
            else
            {
                coin.Tag       = 2;
                coin.PositionX = topPipe.PositionX + 190;
                coin.PositionY = topPipe.PositionY - pipeGap.ContentSize.Height - 120;
            }


            pipeNode.AddChild(coin);
            this.ReorderChild(coin, 10);

            CCAnimation coinAnimation = new CCAnimation();

            for (int i = 1; i <= 4; i++)
            {
                coinAnimation.AddSpriteFrame(new CCSprite(string.Format("gold_{0}", i)));
            }
            coinAnimation.DelayPerUnit = 0.1f;

            var animate         = new CCAnimate(coinAnimation);
            var animationAction = new CCRepeatForever(animate);

            coin.RunAction(animationAction);



            float endPosition  = ContentSize.Width + (pipeNode.ContentSize.Width * 2) + 190;
            var   moveAction   = new CCMoveBy(6.2f, new CCPoint(-endPosition, 0));
            var   remove       = new CCRemoveSelf();
            var   moveSequence = new CCSequence(moveAction, remove);

            pipeNode.RunAction(moveSequence);
        }
		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);
			}	
		}
		/** Adds a CCAnimation with a name.*/
		public void addAnimation(CCAnimation animation, string name){
			_animations.Add (name, animation);
		}
        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);
            }
        }
        public SpriteBatchNodeChildren()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            // parents
            CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini", 50);

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

            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini");

            CCSprite sprite1 = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");

            sprite1.position = (new CCPoint(s.width / 3, s.height / 2));

            CCSprite sprite2 = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png");

            sprite2.position = (new CCPoint(50, 50));

            CCSprite sprite3 = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png");

            sprite3.position = (new CCPoint(-50, -50));

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

            // BEGIN NEW CODE
            List <CCSpriteFrame> 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 = CCAnimation.animationWithFrames(animFrames, 0.2f);

            sprite1.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithAnimation(animation, false)));
            // END NEW CODE

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

            CCActionInterval seq2 = (CCActionInterval)action_rot.reverse();

            sprite2.runAction(CCRepeatForever.actionWithAction(seq2));

            sprite1.runAction((CCAction)(CCRepeatForever.actionWithAction(action_rot)));
            sprite1.runAction((CCAction)(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(action, action_back)))));
            sprite1.runAction((CCAction)(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(action_s, action_s_back)))));
        }