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
            }
        }
        public SpriteBatchNodeOffsetAnchorScale()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

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

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

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

                switch (i)
                {
                case 0:
                    sprite.AnchorPoint = new CCPoint(0, 0);
                    break;

                case 1:
                    sprite.AnchorPoint = new CCPoint(0.5f, 0.5f);
                    break;

                case 2:
                    sprite.AnchorPoint = new CCPoint(1, 1);
                    break;
                }

                point.Position = sprite.Position;

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

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

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

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

                spritesheet.AddChild(sprite, i);

                //animFrames->release();    // win32 : memory leak    2010-0415
            }
        }
예제 #3
0
        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;
        }
예제 #4
0
 public static void PurgeSharedSpriteFrameCache()
 {
     pSharedSpriteFrameCache = null;
 }
 public override void onExit()
 {
     base.onExit();
     CCSpriteFrameCache.sharedSpriteFrameCache().removeUnusedSpriteFrames();
 }
        public SpriteBatchNodeChildrenZ()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            // parents
            CCSpriteBatchNode batch;
            CCSprite          sprite1, sprite2, sprite3;


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

            // test 1
            batch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini", 50);
            addChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            sprite1          = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
            sprite1.position = (new CCPoint(s.width / 3, s.height / 2));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png");
            sprite2.position = (new CCPoint(20, 30));

            sprite3          = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png");
            sprite3.position = (new CCPoint(-20, 30));

            batch.addChild(sprite1);
            sprite1.addChild(sprite2, 2);
            sprite1.addChild(sprite3, -2);

            // test 2
            batch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini", 50);
            addChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            sprite1          = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
            sprite1.position = (new CCPoint(2 * s.width / 3, s.height / 2));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png");
            sprite2.position = (new CCPoint(20, 30));

            sprite3          = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png");
            sprite3.position = (new CCPoint(-20, 30));

            batch.addChild(sprite1);
            sprite1.addChild(sprite2, -2);
            sprite1.addChild(sprite3, 2);

            // test 3
            batch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini", 50);
            addChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            sprite1          = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
            sprite1.position = (new CCPoint(s.width / 2 - 90, s.height / 4));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png");
            sprite2.position = (new CCPoint(s.width / 2 - 60, s.height / 4));

            sprite3          = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png");
            sprite3.position = (new CCPoint(s.width / 2 - 30, s.height / 4));

            batch.addChild(sprite1, 10);
            batch.addChild(sprite2, -10);
            batch.addChild(sprite3, -5);

            // test 4
            batch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini", 50);
            addChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            sprite1          = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
            sprite1.position = (new CCPoint(s.width / 2 + 30, s.height / 4));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png");
            sprite2.position = (new CCPoint(s.width / 2 + 60, s.height / 4));

            sprite3          = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png");
            sprite3.position = (new CCPoint(s.width / 2 + 90, s.height / 4));

            batch.addChild(sprite1, -10);
            batch.addChild(sprite2, -5);
            batch.addChild(sprite3, -2);
        }
예제 #7
0
        public AnimationCache()
        {
            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini");
            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini_gray");
            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini_blue");

            //
            // create animation "dance"
            //
            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 = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str);
                animFrames.Add(frame);
            }

            CCAnimation animation = CCAnimation.animationWithFrames(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++)
            {
                string temp = "";
                if (i < 10)
                {
                    temp = "0" + i;
                }
                else
                {
                    temp = i.ToString();
                }
                str = String.Format("grossini_dance_gray_{0}.png", temp);
                CCSpriteFrame frame = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str);
                animFrames.Add(frame);
            }

            animation = CCAnimation.animationWithFrames(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{0}.png", i);
                CCSpriteFrame frame = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str);
                animFrames.Add(frame);
            }

            animation = CCAnimation.animationWithFrames(animFrames, 0.2f);

            // Add an animation to the Cache
            CCAnimationCache.sharedAnimationCache().addAnimation(animation, "dance_blue");


            CCAnimationCache animCache = CCAnimationCache.sharedAnimationCache();

            CCAnimation normal     = animCache.animationByName("dance");
            CCAnimation dance_grey = animCache.animationByName("dance_gray");
            CCAnimation dance_blue = animCache.animationByName("dance_blue");

            CCAnimate animN = CCAnimate.actionWithAnimation(normal);
            CCAnimate animG = CCAnimate.actionWithAnimation(dance_grey);
            CCAnimate animB = CCAnimate.actionWithAnimation(dance_blue);

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

            // create an sprite without texture
            CCSprite grossini = new CCSprite();

            grossini.init();

            CCSize winSize = CCDirector.sharedDirector().getWinSize();

            grossini.position = (new CCPoint(winSize.width / 2, winSize.height / 2));
            addChild(grossini);

            // run the animation
            grossini.runAction(seq);
        }
예제 #8
0
 public override void onExit()
 {
     base.onExit();
     CCSpriteFrameCache.sharedSpriteFrameCache().removeSpriteFramesFromFile("animations/grossini");
 }
예제 #9
0
        public override void onEnter()
        {
            base.onEnter();
            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 is a cache of CCSpriteFrames
            // CCSpriteFrames each contain a texture id and a rect (frame).

            CCSpriteFrameCache cache = CCSpriteFrameCache.sharedSpriteFrameCache();

            cache.addSpriteFramesWithFile("animations/grossini-aliases", "animations/images/grossini-aliases");

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

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

            sprite.position = (new CCPoint(s.width * 0.5f, s.height * 0.5f));

            CCSpriteBatchNode spriteBatch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini-aliases");

            spriteBatch.addChild(sprite);
            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();
                }
                // Obtain frames by alias name
                str = string.Format("dance_{0}", temp);
                CCSpriteFrame frame = cache.spriteFrameByName(str);
                animFrames.Add(frame);
            }

            CCAnimation animation = CCAnimation.animationWithFrames(animFrames);

            // 14 frames * 1sec = 14 seconds
            sprite.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithDuration(14.0f, animation, false)));
        }
예제 #10
0
        public SpriteOffsetAnchorFlip()
        {
            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, 1);

                switch (i)
                {
                case 0:
                    sprite.AnchorPoint = new CCPoint(0, 0);
                    break;

                case 1:
                    sprite.AnchorPoint = (new CCPoint(0.5f, 0.5f));
                    break;

                case 2:
                    sprite.AnchorPoint = new CCPoint(1, 1);
                    break;
                }

                point.Position = sprite.Position;

                var    animFrames = new List <CCSpriteFrame>();
                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;

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

                AddChild(sprite, 0);
            }
        }
예제 #11
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;
        }
예제 #12
0
 private void ClearCaches()
 {
     CCTextureCache.SharedTextureCache.DumpCachedTextureInfo();
     CCSpriteFrameCache.PurgeSharedSpriteFrameCache();
     CCTextureCache.PurgeSharedTextureCache();
 }
        public SpriteBatchNodeOffsetAnchorFlip()
        {
            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, 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>();
                string tmp = "";
                for (int j = 0; j < 14; j++)
                {
                    string temp = "";
                    if (i + 1 < 10)
                    {
                        temp = "0" + (i + 1);
                    }
                    else
                    {
                        temp = (i + 1).ToString();
                    }
                    tmp = string.Format("grossini_dance_{0}.png", temp);
                    CCSpriteFrame frame = cache.spriteFrameByName(tmp);
                    animFrames.Add(frame);
                }

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

                animFrames = null;

                CCFlipY            flip      = CCFlipY.actionWithFlipY(true);
                CCFlipY            flip_back = CCFlipY.actionWithFlipY(false);
                CCDelayTime        delay     = CCDelayTime.actionWithDuration(1);
                CCFiniteTimeAction seq       = CCSequence.actions((CCFiniteTimeAction)delay, (CCFiniteTimeAction)flip, (CCFiniteTimeAction)delay.copyWithZone(null), (CCFiniteTimeAction)flip_back);
                sprite.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq));

                spritebatch.addChild(sprite, i);
            }
        }
        public SpriteBatchNodeChildrenScale()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

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

            CCNode           aParent;
            CCSprite         sprite1, sprite2;
            CCActionInterval rot = CCRotateBy.actionWithDuration(10, 360);
            CCAction         seq = CCRepeatForever.actionWithAction(rot);

            //
            // Children + Scale using Sprite
            // Test 1
            //
            aParent          = CCNode.node();
            sprite1          = CCSprite.spriteWithSpriteFrameName("grossinis_sister1");
            sprite1.position = new CCPoint(s.width / 4, s.height / 4);
            sprite1.scaleX   = -0.5f;
            sprite1.scaleY   = 2.0f;
            sprite1.runAction(seq);


            sprite2          = CCSprite.spriteWithSpriteFrameName("grossinis_sister2");
            sprite2.position = (new CCPoint(50, 0));

            addChild(aParent);
            aParent.addChild(sprite1);
            sprite1.addChild(sprite2);


            //
            // Children + Scale using SpriteBatchNode
            // Test 2
            //

            aParent          = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini_family");
            sprite1          = CCSprite.spriteWithSpriteFrameName("grossinis_sister1");
            sprite1.position = new CCPoint(3 * s.width / 4, s.height / 4);
            sprite1.scaleX   = -0.5f;
            sprite1.scaleY   = 2.0f;
            sprite1.runAction((CCAction)(seq.copy()));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossinis_sister2");
            sprite2.position = (new CCPoint(50, 0));

            addChild(aParent);
            aParent.addChild(sprite1);
            sprite1.addChild(sprite2);


            //
            // Children + Scale using Sprite
            // Test 3
            //

            aParent          = CCNode.node();
            sprite1          = CCSprite.spriteWithSpriteFrameName("grossinis_sister1");
            sprite1.position = (new CCPoint(s.width / 4, 2 * s.height / 3));
            sprite1.scaleX   = (1.5f);
            sprite1.scaleY   = -0.5f;
            sprite1.runAction((CCAction)(seq.copy()));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossinis_sister2");
            sprite2.position = (new CCPoint(50, 0));

            addChild(aParent);
            aParent.addChild(sprite1);
            sprite1.addChild(sprite2);

            //
            // Children + Scale using Sprite
            // Test 4
            //

            aParent          = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini_family");
            sprite1          = CCSprite.spriteWithSpriteFrameName("grossinis_sister1");
            sprite1.position = (new CCPoint(3 * s.width / 4, 2 * s.height / 3));
            sprite1.scaleX   = 1.5f;
            sprite1.scaleY   = -0.5f;
            sprite1.runAction((CCAction)(seq.copy()));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossinis_sister2");
            sprite2.position = (new CCPoint(50, 0));

            addChild(aParent);
            aParent.addChild(sprite1);
            sprite1.addChild(sprite2);
        }
        public SpriteChildrenChildren()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

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

            CCNode           aParent;
            CCSprite         l1, l2a, l2b, l3a1, l3a2, l3b1, l3b2;
            CCActionInterval rot = CCRotateBy.actionWithDuration(10, 360);
            CCAction         seq = CCRepeatForever.actionWithAction(rot);

            CCActionInterval rot_back    = (CCActionInterval)rot.reverse();
            CCAction         rot_back_fe = CCRepeatForever.actionWithAction(rot_back);

            //
            // SpriteBatchNode: 3 levels of children
            //

            aParent = CCNode.node();
            addChild(aParent);

            // parent
            l1          = CCSprite.spriteWithSpriteFrameName("father.gif");
            l1.position = (new CCPoint(s.width / 2, s.height / 2));
            l1.runAction((CCAction)(seq.copy()));
            aParent.addChild(l1);
            CCSize l1Size = l1.contentSize;

            // child left
            l2a          = CCSprite.spriteWithSpriteFrameName("sister1.gif");
            l2a.position = (new CCPoint(-50 + l1Size.width / 2, 0 + l1Size.height / 2));
            l2a.runAction((CCAction)(rot_back_fe.copy()));
            l1.addChild(l2a);
            CCSize l2aSize = l2a.contentSize;

            // child right
            l2b          = CCSprite.spriteWithSpriteFrameName("sister2.gif");
            l2b.position = (new CCPoint(+50 + l1Size.width / 2, 0 + l1Size.height / 2));
            l2b.runAction((CCAction)(rot_back_fe.copy()));
            l1.addChild(l2b);
            CCSize l2bSize = l2a.contentSize;

            // child left bottom
            l3a1          = CCSprite.spriteWithSpriteFrameName("child1.gif");
            l3a1.scale    = 0.45f;
            l3a1.position = new CCPoint(0 + l2aSize.width / 2, -100 + l2aSize.height / 2);
            l2a.addChild(l3a1);

            // child left top
            l3a2          = CCSprite.spriteWithSpriteFrameName("child1.gif");
            l3a2.scale    = 0.45f;
            l3a1.position = (new CCPoint(0 + l2aSize.width / 2, +100 + l2aSize.height / 2));
            l2a.addChild(l3a2);

            // child right bottom
            l3b1          = CCSprite.spriteWithSpriteFrameName("child1.gif");
            l3b1.scale    = 0.45f;
            l3b1.IsFlipY  = true;
            l3b1.position = (new CCPoint(0 + l2bSize.width / 2, -100 + l2bSize.height / 2));
            l2b.addChild(l3b1);

            // child right top
            l3b2          = CCSprite.spriteWithSpriteFrameName("child1.gif");
            l3b2.scale    = 0.45f;
            l3b2.IsFlipY  = true;
            l3b1.position = new CCPoint(0 + l2bSize.width / 2, +100 + l2bSize.height / 2);
            l2b.addChild(l3b2);
        }
예제 #16
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);
            }
        }
예제 #17
0
        public SpriteBatchNodeChildren2()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

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

            batch.Texture.generateMipmap();

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

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


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

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

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

            sprite12.position = (new CCPoint(20, 30));
            sprite12.scale    = 0.2f;

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

            sprite13.position = (new CCPoint(-20, 30));
            sprite13.scale    = 0.2f;

            batch.addChild(sprite11);
            sprite11.addChild(sprite12, -2);
            sprite11.addChild(sprite13, 2);

            // don't rotate with it's parent
            sprite12.honorParentTransform = ((ccHonorParentTransform)(sprite12.honorParentTransform & ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_TRANSLATE));

            // don't scale and rotate with it's parent
            sprite13.honorParentTransform = ((ccHonorParentTransform)(sprite13.honorParentTransform & (ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_SCALE | ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_ROTATE)));

            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();

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

            //
            // another set of parent / children
            //

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

            sprite21.position = (new CCPoint(2 * s.width / 3, s.height / 2 - 50));

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

            sprite22.position = (new CCPoint(20, 30));
            sprite22.scale    = 0.8f;

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

            sprite23.position = (new CCPoint(-20, 30));
            sprite23.scale    = 0.8f;

            batch.addChild(sprite21);
            sprite21.addChild(sprite22, -2);
            sprite21.addChild(sprite23, 2);

            // don't rotate with it's parent
            sprite22.honorParentTransform = ((ccHonorParentTransform)(sprite22.honorParentTransform & ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_TRANSLATE));

            // don't scale and rotate with it's parent
            sprite23.honorParentTransform = ((ccHonorParentTransform)(sprite23.honorParentTransform & ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_SCALE));

            sprite21.runAction(CCRepeatForever.actionWithAction(CCRotateBy.actionWithDuration(1, 360)));
            sprite21.runAction(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(CCScaleTo.actionWithDuration(0.5f, 5.0f), CCScaleTo.actionWithDuration(0.5f, 1)))));
        }
        public SpriteBatchNodeOffsetAnchorSkewScale()
        {
            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;

                // skew
                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 = new CCSequence(skewX, skewX_back, skewY, skewY_back);
                sprite.RunAction(new CCRepeatForever((CCActionInterval)seq_skew));

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

                spritebatch.AddChild(sprite, i);
            }
        }
        public SpriteBatchNodeChildrenAnchorPoint()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

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

            CCNode   aParent;
            CCSprite sprite1, sprite2, sprite3, sprite4, point;

            //
            // SpriteBatchNode
            //
            // parents

            aParent = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini", 50);
            addChild(aParent, 0);

            // anchor (0,0)
            sprite1             = CCSprite.spriteWithSpriteFrameName("grossini_dance_08.png");
            sprite1.position    = (new CCPoint(s.width / 4, s.height / 2));
            sprite1.anchorPoint = (new CCPoint(0, 0));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png");
            sprite2.position = (new CCPoint(20, 30));

            sprite3          = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png");
            sprite3.position = (new CCPoint(-20, 30));

            sprite4          = CCSprite.spriteWithSpriteFrameName("grossini_dance_04.png");
            sprite4.position = (new CCPoint(0, 0));
            sprite4.scale    = 0.5f;

            aParent.addChild(sprite1);
            sprite1.addChild(sprite2, -2);
            sprite1.addChild(sprite3, -2);
            sprite1.addChild(sprite4, 3);

            point          = CCSprite.spriteWithFile("Images/r1");
            point.scale    = 0.25f;
            point.position = sprite1.position;
            addChild(point, 10);


            // anchor (0.5, 0.5)
            sprite1             = CCSprite.spriteWithSpriteFrameName("grossini_dance_08.png");
            sprite1.position    = (new CCPoint(s.width / 2, s.height / 2));
            sprite1.anchorPoint = (new CCPoint(0.5f, 0.5f));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png");
            sprite2.position = (new CCPoint(20, 30));

            sprite3          = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png");
            sprite3.position = (new CCPoint(-20, 30));

            sprite4          = CCSprite.spriteWithSpriteFrameName("grossini_dance_04.png");
            sprite4.position = (new CCPoint(0, 0));
            sprite4.scale    = 0.5f;

            aParent.addChild(sprite1);
            sprite1.addChild(sprite2, -2);
            sprite1.addChild(sprite3, -2);
            sprite1.addChild(sprite4, 3);

            point          = CCSprite.spriteWithFile("Images/r1");
            point.scale    = 0.25f;
            point.position = sprite1.position;
            addChild(point, 10);


            // anchor (1,1)
            sprite1             = CCSprite.spriteWithSpriteFrameName("grossini_dance_08.png");
            sprite1.position    = (new CCPoint(s.width / 2 + s.width / 4, s.height / 2));
            sprite1.anchorPoint = (new CCPoint(1, 1));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png");
            sprite2.position = (new CCPoint(20, 30));

            sprite3          = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png");
            sprite3.position = (new CCPoint(-20, 30));

            sprite4          = CCSprite.spriteWithSpriteFrameName("grossini_dance_04.png");
            sprite4.position = (new CCPoint(0, 0));
            sprite4.scale    = 0.5f;

            aParent.addChild(sprite1);
            sprite1.addChild(sprite2, -2);
            sprite1.addChild(sprite3, -2);
            sprite1.addChild(sprite4, 3);

            point          = CCSprite.spriteWithFile("Images/r1");
            point.scale    = 0.25f;
            point.position = sprite1.position;
            addChild(point, 10);
        }
예제 #20
0
 public static void InitializeResource()
 {
     CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("GameUI01", "images/GameUI01");
     CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("GameUI02", "images/GameUI02");
 }
        public SpriteOffsetAnchorScale()
        {
            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, 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>(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.spriteFrameByName(str);
                    animFrames.Add(frame);
                }

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

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

                addChild(sprite, 0);

                //animFrames->release();    // win32 : memory leak    2010-0415
            }
        }